国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)

這篇具有很好參考價值的文章主要介紹了微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

百度地圖微信小程序JavaScript API(簡稱小程序JSAPI),支持在微信小程序中使用百度數(shù)據(jù)資源。小程序JSAPI是對百度地圖Web服務(wù)API中的部分接口按照微信小程序的規(guī)范進(jìn)行了前端JS封裝,方便了微信小程序開發(fā)者的調(diào)用。部分接口對返回的POI等數(shù)據(jù)按照微信小程序的數(shù)據(jù)格式進(jìn)行了處理,可直接用于小程序的map中。

一、環(huán)境部署

1.need to be declared in the requiredPrivateInfos

wx.getLocation need to be declared in the requiredPrivateInfos field in app.json/ext.json(env: Windows,mp,1.06.2303220; lib: 2.31.1)

官方說明:
requiredPrivateInfos

自 2022 年 7 月 14 日后發(fā)布的小程序,使用以下8個地理位置相關(guān)接口時,需要聲明該字段,否則將無法正常使用申明需要使用的地理位置相關(guān)接口,類型為數(shù)組。
目前支持以下項(xiàng)目:

  • getFuzzyLocation: 獲取模糊地理位置
  • getLocation: 獲取精確地理位置
  • onLocationChange: 監(jiān)聽實(shí)時地理位置變化事件
  • startLocationUpdate: 接收位置消息(前臺
  • startLocationUpdateBackground:
  • 接收位置消息(前后臺) chooseLocation: 打開地圖選擇位置
  • choosePoi: 打開POI列表選擇位置
  • chooseAddress: 獲取用戶地址信息

注:若使用以上接口,均需在小程序管理后臺,「開發(fā)」-「開發(fā)管理」-「接口設(shè)置」中自助開通該接口權(quán)限。

微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)

微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)

    "requiredPrivateInfos": [
        "getLocation",
        "onLocationChange",
        "startLocationUpdateBackground",
        "chooseAddress"
    ],

2.api.map.baidu.com 不在以下 request 合法域名

https://api.map.baidu.com 不在以下 request 合法域名列表中,請參考文檔:https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html

微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)
解決方案:
設(shè)置請求合法域名,才能正常使用百度小程序 JavaScript API。
登錄微信小程序-> “設(shè)置” -> “開發(fā)設(shè)置” -> “服務(wù)器域名” ->添加 https://api.map.baidu.com; -> 點(diǎn)擊"保存并提交"。

3.width and heigth of marker id 9 are required

[渲染層錯誤] [Component] : width and heigth of marker id 9 are required(env: Windows,mp,1.06.2303220; lib: 2.31.1)

微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)
微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)

二、核心代碼

鑒于百度地圖微信小程序依然是基于騰訊地圖map組件開發(fā)的,因此在功能的拓展性、更新速度都不很理想。本案例是基于百度地圖微信小程序的基礎(chǔ),予以開發(fā)。

  1. wx.showModal,彈窗功能
  2. POI坐標(biāo)單擊更換顏色功能(百度地圖原有功能);
  3. wx.openLocation,導(dǎo)航(支持騰訊、百度、高德、APPLE地圖功能)

微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)
電腦端的導(dǎo)航和手機(jī)端預(yù)覽導(dǎo)航有差異,見下圖:
微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)

(一)邏輯層index.js

  1. 引入百度地圖API接口,并配置全局變量
var bmap = require('../../libs/bmap-wx.min.js');
var wxMarkerData = [];
  1. Marker單擊事件
 //POI單擊事件
    makertap: function (e) {
        var that = this;
        var id = e.markerId;
        that.showSearchInfo(wxMarkerData, id);
        that.changeMarkerColor(wxMarkerData, id);
    },
  1. 引入百度地圖對象
    此處的AK為對應(yīng)的微信小程序的key.
 //加載即引入百度地圖
    onLoad: function () {
        //引入百度地圖對象
        var that = this;
        var BMap = new bmap.BMapWX({
            ak: 'OGwPpKV6Y6GiLb3***'
        });
        var fail = function (data) {
            console.log(data)
        };
        //獲取POI數(shù)據(jù)
        this.getMarkers()
    },
  1. 調(diào)用API數(shù)據(jù)接口
//調(diào)用API數(shù)據(jù)接口
    getMarkers() {
        var that = this;
        wx.request({
            url: 'https://test.com/data/api/marker.json',
            method: "GET",
            success: function (res) {
                wxMarkerData = res.data.data
                //console.log(wxMarkerData)
                that.setData({
                    markers: wxMarkerData,
                    latitude: wxMarkerData[0].latitude,
                    longitude: wxMarkerData[0].longitude
                });
            },
            fail: function (err) {
                console.log(err)
            }
        })
    },

數(shù)據(jù)格式如下:
微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)
5. 彈窗及導(dǎo)航事件函數(shù)

  //點(diǎn)擊顯示信息,調(diào)整為新窗口
    showSearchInfo: function (data, i) {
        wx.showModal({
            title: data[i].title,
            content: data[i].address,
            showCancel: true, //是否顯示取消按鈕
            cancelText: "關(guān)閉", //默認(rèn)是“取消”
            cancelColor: '#000', //取消文字的顏色
            confirmText: "導(dǎo)航", //默認(rèn)是“確定”
            confirmColor: '#000', //確定文字的顏色
            success(res) {
                if (res.confirm) {
                    console.log('用戶點(diǎn)擊導(dǎo)航')
                    let latitude = parseFloat(data[i].latitude)
                    let longitude = parseFloat(data[i].longitude)
                    let name = data[i].title
                    let address = data[i].address
                    wx.openLocation({
                        latitude,
                        longitude,
                        name,
                        address,
                        scale: 18
                    })
                } else if (res.cancel) {
                    console.log('用戶點(diǎn)擊關(guān)閉')
                }
            }
        })
    },
  1. 單擊更換圖標(biāo)函數(shù)
 //單擊更換圖標(biāo)
    changeMarkerColor: function (data, id) {
        var that = this;
        var markersTemp = [];
        for (var i = 0; i < data.length; i++) {
            if (i === id) {
                data[i].iconPath = "../../img/marker_yellow.png";
            } else {
                data[i].iconPath = "../../img/marker_red.png";
            }
            markersTemp[i] = data[i];
        }
        that.setData({
            markers: markersTemp
        });
    }

(二)渲染層index.wxml

<view class="map_container">
    <map class="map" id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="14" show-location="true" markers="{{markers}}" bindmarkertap="makertap"></map>
</view>

(三)樣式表index.wxss

.map_container{
    height: 100vh;
    width: 100%;
}

.map {
    height: 100%;
    width: 100%;
}

@漏刻有時文章來源地址http://www.zghlxwxcb.cn/news/detail-432613.html

到了這里,關(guān)于微信小程序?qū)W習(xí)實(shí)錄3(環(huán)境部署、百度地圖微信小程序、單擊更換圖標(biāo)、彈窗信息、導(dǎo)航、支持騰訊百度高德地圖調(diào)起)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包