小程序 map地图多点定位

  <map id="myMap" latitude="{{latitude}}" 
  longitude="{{longitude}}" 
  markers="{{markers}}" 
  show-location 
  bindmarkertap="selectMarket"
  include-points="{{markers}}"></map>

var app = getApp();
Page({
  data: {
    latitude: 22.15792,  // latitude	纬度
    longitude: 113.564344, // longitude	经度
    markers:
    [
  {
    id: 0,
    latitude: 22.15792,
    longitude: 113.564344,
    name: '酒店1',
    callout: {
      content: " 酒店1 \n 230元/晚",
      padding: 10,
      display: 'ALWAYS',
      textAlign: 'center',
      borderRadius: 10,
      borderWidth: 1,
    }
  },
  {
    id: 1,
    latitude: 22.164866,
    longitude: 113.570039,
    name: '酒店2',
    callout: {
      content: "酒店2",
      padding: 10,
      display: 'ALWAYS',
      textAlign: 'center',
      borderRadius: 10,
      borderWidth: 1,
    }
  },
  {
    id: 2,
    latitude: 22.162828,
    longitude: 113.567883,
    name: '酒店3',
    callout: {
      content: " 酒店3",
      padding: 10,
      display: 'ALWAYS',
      textAlign: 'center',
      borderRadius: 10,
      borderWidth: 1,
    }
  },
]
  },
  selectMarket: function (e) {
    console.log(e)
    var id = e.markerId
    console.log(id)
    wx.openLocation({
      latitude: this.data.markers[id].latitude,
      longitude: this.data.markers[id].longitude,
      name: this.data.markers[id].name,
    })
  },
  onLoad: function (options) {
    // 这里请求接口
  },
});

发布了128 篇原创文章 · 获赞 3 · 访问量 2576

猜你喜欢

转载自blog.csdn.net/qq_26642611/article/details/103720311