北京网站优化专家,网络营销模式分析,做外贸网站的经验,织梦网站被做跳转DAY13
1、使用map组件在页面中创建地图后#xff0c;若想在JS文件中对地图进行控制#xff0c;需要通过地图API来完成。先通过wx.createMapContext()方法创建MapContext#xff08;Map上下文#xff09;实例#xff0c;然后通过该实例的相关方法来操作map组件。
const m…DAY13
1、使用map组件在页面中创建地图后若想在JS文件中对地图进行控制需要通过地图API来完成。先通过wx.createMapContext()方法创建MapContextMap上下文实例然后通过该实例的相关方法来操作map组件。
const mapCtxwx.createMapContext(‘myMap’)
表52MapContext实例的常用方法 方法 说明 getCenterLocation() 获取当前地图中心的经纬度返回GCJ-02坐标 moveToLaction() 将地图中心移至当前定位点
表53getCenterLocation()方法的常用选项 选项 类型 说明 iconPath string 图标路径支持网络路径、本地路径、代码包路径 success function 接口调用成功的回调函数通过其参数可以获取longitude经度和latitude纬度 fail function 接口调用失败的回调函数 complete function 接口调用结束的回调函数
表54moveToLocation()方法的常用选项 选项 类型 说明 longitude number 经度 latitude number 纬度 success function 接口调用成功的回调函数 fail function 接口调用失败的回调函数 complete function 接口调用结束的回调函数
2、如何使用MapContext实例获取当前地图中心的经纬度 mapCtx.getCenterLocation({ success:res{ const longituderes.longitude const latituderes.latitude console.log(longitude,latitude) } })