微信小程序 地图组件使用
生活随笔
收集整理的這篇文章主要介紹了
微信小程序 地图组件使用
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?本地圖程序利用map組件,以及使用它的markers,polyline屬性分別設(shè)置地圖兩個(gè)位置的標(biāo)志以及他們之間的連線,利用騰訊地圖的API對兩個(gè)地點(diǎn)進(jìn)行查詢,動(dòng)態(tài)設(shè)置地圖的經(jīng)緯度,以及動(dòng)態(tài)初始化markers,polyline屬性。
程序運(yùn)行截圖如下:
程序代碼如下:
?2.?map/index.js
// pages/Map/index.js var QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js'); var qqmapsdk = new QQMapWX({ key: 'GEYBZ-IM4WJ-TK5FL-K7BKW-TDDV2-P5FGL'}); Page({/** * 頁面的初始數(shù)據(jù) */ data: { start_lat: 0, start_lon: 0, end_lat:0, end_lon:0, markers: [ { iconPath: '../../utils/images/qz.jpg', id: 0, latitude: 0, longitude: 0, width: 50, height: 50 }, { iconPath: '../../utils/images/qz.jpg', id: 1, latitude: 0, longitude: 0, width: 50, height: 50 } ], address: '', polyline: [ { points: [{ longitude: 0, latitude: 0}, { latitude: 0, longitude: 0 }], color: "#ff6600", width: 2, dottedLine: false, arrowLine: true, borderColor: "#000", borderWidth: 5 } ] }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function (options) { var that = this; let start_lat=0; let start_lon=0; wx.getLocation({ success: function (res) { qqmapsdk.search({ keyword: '江西省南昌市新建區(qū)豐和南大道696號', complete: function (res) { console.log(res.data[0].location.lat); console.log(res.data[0].location.lng); start_lat = res.data[0].location.lat; start_lon = res.data[0].location.lng; that.setData({ start_lat: res.data[0].location.lat, start_lon: res.data[0].location.lng, "markers[0].latitude": res.data[0].location.lat, "markers[0].longitude": res.data[0].location.lng, "polyline[0].points[0].latitude": res.data[0].location.lat, "polyline[0].points[0].longitude": res.data[0].location.lng, }) } }); qqmapsdk.search({ keyword: '江西省南昌市新建區(qū)紅谷灘新區(qū)學(xué)府大道999號', complete: function (res) { that.setData({ end_lat: res.data[0].location.lat, end_lon: res.data[0].location.lng, "markers[1].latitude": res.data[0].location.lat, "markers[1].longitude": res.data[0].location.lng, "polyline[0].points[1].latitude": res.data[0].location.lat, "polyline[0].points[1].longitude": res.data[0].location.lng, // polyline: [{ // points: [{ // longitude: res.data[0].location.lng, // latitude: res.data[0].location.lat// }, { // latitude: that.data.start_lat, // longitude: that.data.start_lon // }], // color: "#ff6600", // width: 2, // dottedLine: false, // arrowLine: true, // borderColor: "#000", // borderWidth: 5 // }] }); } })}, })}, /** * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 */ onReady: function () {},/** * 生命周期函數(shù)--監(jiān)聽頁面顯示 */ onShow: function () {},/** * 生命周期函數(shù)--監(jiān)聽頁面隱藏 */ onHide: function () {},/** * 生命周期函數(shù)--監(jiān)聽頁面卸載 */ onUnload: function () {},/** * 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作 */ onPullDownRefresh: function () {},/** * 頁面上拉觸底事件的處理函數(shù) */ onReachBottom: function () {},/** * 用戶點(diǎn)擊右上角分享 */ onShareAppMessage: function () {} })???????? ?3.?map/index.wxml
<map class='map' latitude='{{start_lat}}' longitude='{{start_lon}}' polyline="{{polyline}}" markers='{{markers}}'> </map>? ?4.??map/index.wxss
page{ width: 100%; height: 100%; } .map{ height: 100%; width: 100%; }?
總結(jié)
以上是生活随笔為你收集整理的微信小程序 地图组件使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html语言重点,HTML 基础重点(1
- 下一篇: Hive解题思路