微信小程序地图操作比较简单api也很少使用map组件来展示。说到地图网店建设使用map组件来展示。说到地图那就先来看基础定位:
定位用到wx.getLocation(OBJECT)函数代码如下:
map属性太多先看一下:
如果用到地图基本上所有属性都会用到。 下面一一看一下我们先看效果图吧先看真相:
这里我只用了一个markers就是定位当前位置的红色markers用法如下:
wx.getLocation({
type: 'wgs84', // 默认为 wgs84 返回 gps 坐标gcj02 返回可用于 wx.openLocation 的坐标
success: function (res) {
_this.setData({
latitude: res.latitude,
longitude: res.longitude,
markers: [{
id: "1",
latitude: res.latitude,
longitude: res.longitude,
width: 50,
height: 50,
iconPath: "/assests/imgs/my.png",
title: "哪里"
}],
circles: [{
latitude: res.latitude,
longitude: res.longitude,
color: '#FF0000DD',
fillColor: '#7cb5ec88',
radius: 3000,
strokeWidth: 1
}]
})
}
})
这里加了circles半径是3000米具体的api可自行看官网。
接下来看看controls控制层在地图上显示控件控件不随着地图移动看API:
注意看示例图的右上角有两个按钮加减号是控制地图scale的数值变化网站架设是控制地图scale的数值变化动态缩放地图的controls用法也很简单:
controls: [{
id: 1,
iconPath: '/assests/imgs/jian.png',
position: {
left: 320,
top: 100 - 50,
width: 20,
height: 20
},
clickable: true
},
{
id: 2,
iconPath: '/assests/imgs/jia.png',
position: {
left: 340,
top: 100 - 50,
width: 20,
height: 20
},
clickable: true
}
]
最后我们看一张gif图: