国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序?qū)崿F(xiàn)定位及到指定位置導航的示例代碼

2024-07-22 01:17:41
字體:
來源:轉載
供稿:網(wǎng)友

一:實現(xiàn)定位及到指定位置導航所需組件及API

1:組件:map(地圖組件)

2:API:wx.getLocation(Object object)(獲取當前的地理位置、速度),wx.openLocation(Object object)(使用微信內(nèi)置地圖查看位置)

二:代碼實現(xiàn)

1:wxml

<view><map id="map"longitude="{{longitude}}"latitude="{{latitude}}"scale="14"markers="{{markers}}"bindmarkertap="markertap"bindregionchange="regionchange"show-locationstyle="width: 100%; height: 300px;"></map></view><view><button type="primary" bindtap="navigate">導航</button></view>

2:js

//jsPage({/**  * 頁面的初始數(shù)據(jù)  */data: {//設置標記點markers: [{iconPath: "/images/ljx.png",id: 4,latitude: 31.938841,longitude: 118.799698,width: 30,height: 30}],//當前定位位置latitude:'',longitude: '',},navigate() {////使用微信內(nèi)置地圖查看標記點位置,并進行導航wx.openLocation({latitude: this.data.markers[0].latitude,//要去的緯度-地址longitude: this.data.markers[0].longitude,//要去的經(jīng)度-地址})},onLoad() {//獲取當前位置wx.getLocation({type: 'gcj02',success: (res) => {console.log(res)this.setData({latitude: res.latitude,longitude: res.longitude})}})}})

根據(jù)如上即可實現(xiàn)自身定位及到指定位置的導航,如下:




以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 四平市| 台山市| 平邑县| 綦江县| 迁西县| 盐源县| 福泉市| 富川| 淅川县| 嘉义县| 敖汉旗| 土默特右旗| 扬州市| 政和县| 成武县| 汾阳市| 清丰县| 鸡东县| 桃园市| 隆昌县| 浦东新区| 安图县| 姜堰市| 宿迁市| 宁明县| 乌拉特后旗| 淮滨县| 措美县| 常熟市| 简阳市| 松溪县| 开远市| 文安县| 六安市| 岳西县| 缙云县| 瓮安县| 弥勒县| 安吉县| 紫阳县| 朝阳区|