微信小程序小程序微信小程序开发

使用小程序内置地图wx.getLocation和wx.openL

2018-09-26  本文已影响6人  前端来入坑
//wxml
<button type="default" bindtap="openMap">打开地图</button>
//js
Page({
  data: {

  },
  openMap: function () {
    wx.getLocation({
      type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
      success: function (res) {
        // success
        console.log(res.latitude);
        console.log(res.longitude);
        wx.openLocation({
          latitude: res.latitude, // 纬度,范围为-90~90,负数表示南纬
          longitude: res.longitude, // 经度,范围为-180~180,负数表示西经
          scale: 28, // 缩放比例
          name:"要找的地方名字(某某饭店)",
          address:"地址:要去的地点详细描述"
        })
      }
    })
  }
})

效果


image.png

点击按钮后效果


image.png

官方API地址:https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.openLocation.html

上一篇 下一篇

猜你喜欢

热点阅读