微信小程序 引用 map 地图,显示当前位置
生活随笔
收集整理的這篇文章主要介紹了
微信小程序 引用 map 地图,显示当前位置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、定位用到?wx.getLocation?函數,地圖使用?map組件,詳細教程參照官網; 注意事項:在給經度 和緯度賦值時,千萬不能賦錯;
2、先看下效果圖:
3、在wxml頁面定義map組件,包含?longitude、latitude、markers、scale、
show-location屬性,并設置了 寬度和高度自適應(由于我設置了page是100%,所以我這里高度設置100%就是自適應容器高度了),代碼如下: wxml: <view class="" hover-class="none" hover-stop-propagation="false" style="width: 100%; height: 100%;"><map id="map" longitude="{{longitude}}" latitude=" {{latitude}}" markers="{{markers}}" scale="13" show-location style="width: 100%; height: 100%;"></map>{{longitude}}</view>? ? ?wxss:
page{height: 100%; }? ? js:
Page({data:{longitude: 113.324520,latitude: 23.099994,markers:[{id: 0,iconPath: "../../images/icon_cur_position.png",latitude: 23.099994,longitude: 113.324520,width: 50,height: 50}]},onLoad: function(){var that = this;wx.getLocation({type: "wgs84",success: function(res){var latitude = res.latitude;var longitude = res.longitude;//console.log(res.latitude); that.setData({latitude: res.latitude,longitude: res.longitude,markers:[{latitude: res.latitude,longitude: res.longitude}]})}})},onReady: function(){}})?
?
轉載于:https://www.cnblogs.com/siyecao2010/p/9476277.html
總結
以上是生活随笔為你收集整理的微信小程序 引用 map 地图,显示当前位置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: chapter3.1封装和解构
- 下一篇: 流式套接字(SOCK_STREAM),数