微信小程序 Map的简单使用

作者: 周南城 | 来源:发表于2018-07-04 14:14 被阅读12次

map.wxml

<view>
  <map class='map' latitude='{{latitude}}' longitude='{{longitude}}' scale='{{scale}}' markers='{{markers}}'/>
</view>

map.wxss

.map{
  width: 100%;
  height: 500rpx;
}

map.js

const app = getApp()

Page({
  data: {
    scale: 18,
    latitude: "",
    longitude: "",
    markers: [],
  },

  onLoad: function () {
    var that = this;
    wx.getLocation({
      success: function (res) {
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude,
          markers: [{
            id: "1",
            latitude: res.latitude,
            longitude: res.longitude,
            width: 20,
            height: 20,
            iconPath: "/resources/img/ic_marker.png"
          }],
        })
      },
    })
  }
})

效果

image

相关文章

网友评论

  • d64a58671073:当前位置定位 不准啊。引入的是腾讯地图吗?
    周南城:wx.getLocation我这里其实定位也不太准,好像是个bug的噢。没有用腾讯地图

本文标题:微信小程序 Map的简单使用

本文链接:https://www.haomeiwen.com/subject/wrueuftx.html