1 去百度api申请定位密钥
https://lbsyun.baidu.com/index.php?title=android-locsdk/guide/create-project/key
2 在项目中添加支持
github:https://github.com/aruis/cordova-plugin-baidumaplocation
ionic cordova platform rm android
ionic cordova plugin rm cordova-plugin-baidumaplocation
ionic cordova plugin add cordova-plugin-baidumaplocation@3.2.0 –variable ANDROID_KEY=”12321121” –variable IOS_KEY=value
3 核心代码
在顶端声明:declare const baidumap_location: any;
if (typeof baidumap_location === “undefined”) {
alert(“baidumap_location is undefined”);
return;
};
baidumap_location.getCurrentPosition(function (result) {
alert(JSON.stringify(result, null, 4));
}, function (error) {
alert(error);
});
ionic g provider LocationTracker
ionic plugin add cordova-plugin-geolocation
npm install –save @ionic-native/geolocation
ionic plugin add cordova-plugin-mauron85-background-geolocation
npm install –save @ionic-native/background-geolocation