在微信开发文档给出的信息来看,它使用的是高德地图的api。我们来到高德地图的官方坐标拾取器界面,得到示例坐标。
我们在组件中放上map组件,这里提及一下,两个官方要求的注意点:
请注意原生组件使用限制。tip
:map
组件使用的经纬度是火星坐标系,调用wx.getLocation
接口需要指定type
为gcj02。
wxml文件
<view class="container"><map id="map" longitude="120.640509" latitude="31.304899" scale="14" markers="{{markers}}" style="width:100%;height:300px;"></map></view>
longitude:中心点经度,Number类型
latitude:中心点纬度,Number类型
scale:缩放级别,取值范围5-18
markers:标记点,js文件定义,包含经纬度等属性
style:组件样式
js文件
Page({data: {markers: [{iconPath: "/theme/v1.3/markers/b/mark_bs.png",id: 0,longitude: 120.640509,latitude: 31.304899,width: 19,height: 33}]}})
iconPath:标记图标路径
id:标记点id,建议每个标记点一个
longitude:经度
latitude:纬度
width:宽度
height:高度
还可以设置其他属性,见官方参考文档https://developers./miniprogram/dev/component/map.html#map
效果图: