获取当前位置
可选option: LocationOption定位选项
const amapLoc = ymx.requirePlugin('ymx-amap-location') as YmxAmapLocation;
// 单次定位
amapLoc.getCurrentPosition({
timeout: 10,
locationMode: 1
}).then(res => {
console.log(`经度: ${res.longitude}, 纬度: ${res.latitude}`);
}).catch(err => {
console.error(err);
});
// 监听连续定位结果
amapLoc.setListener((eventName, res) => {
if (eventName === 'location') {
console.log('实时位置:', res);
}
});
// 开启连续定位
amapLoc.getCurrentPosition({
watch: true,
watchInterval: 3
});
移除监听器
设置监听器,接收 eventName 事件名称,data 事件数据
注意: 此接口为覆盖操作,仅保留最后一个监听器,最后的 listener 才能收到事件通知。
高德定位服务
示例