300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 微信小程序 引用 map 地图 显示当前位置

微信小程序 引用 map 地图 显示当前位置

时间:2019-10-26 07:31:38

相关推荐

微信小程序 引用 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(){}})

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。