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

微信小程序 Map的简单使用

2018-07-04  本文已影响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
上一篇下一篇

猜你喜欢

热点阅读