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