微信小程序获取当前地址以及选择地址详解 地点标记

首先定义事件:

bindtap='getLocation'
<view class='store-bot' bindtap='getLocation'>
      <view class='coll-img botimg'>
        <image src='/images/dizhi.png'></image>
      </view>
      <text>地址:广西贵港市港北区仙衣路212号</text>
    </view>

  然后:在js里写方法

打印出来的信息

 

 想要标记哪个地点 要取得位置的经纬度

然后

ps:工作的时候 店申请入驻 都要获取他店位置的经纬度保存;用于到后面显示该店位置时,把经纬度赋值回openLocation方法里的

latitude: ??? 赋值回来的纬度
longitude: ???赋值回来的经度
scale: 18,
 
放一下js代码 避免手打哈哈哈
// 点击选择地图标记
  getLocation() {
    wx.getLocation({
      type: "wgs84",
      success: function(res) {
        console.log(res);
        wx.openLocation({
          latitude: 37.4511496153052,
          longitude: 105.69409847259521,
          scale: 18,
        })
      },
      fail: function(err) {
        console.log(err)
      }
    })
  },

  

posted @ 2019-01-08 17:29  好感度满减  阅读(3435)  评论(0编辑  收藏  举报