1.ionic项目打包apk,通过apk查看对应的sha1签名(可以通过androstudio,或者解压apk,cmd命令行进入\META-INF文件夹,执行keytool -printcert -file CERT.RSA可查看),在高德地图获取key中 ,发布版安全sha1和调试版安全码都用这个,这样就可以获取正确的key(之前不懂在这个key上花了好久时间)
2给ionic项目搭建高德地图环境
cordova plugin add https://github.com/DaiHuaXieHuaKai/GaoDeLocation.git --variable API_KEY=xxxxx(高德地图申请的key)
npm install @ionic-native/gao-de-location
然后就是引用了
app.module.ts
import { GaoDeLocation } from '@ionic-native/gao-de-location/ngx';
@NgModule({
...
providers: [
GaoDeLocation,
.....
],
...
})
在需要的组件或者页面
xxx.ts
import { GaoDeLocation,PositionOptions,LocationProtocolEnum,LocationModeEnum,DesiredAccuracyEnum,PositionRes } from '@ionic-native/gao-de-location/ngx';
constructor( public gaoDeLocation: GaoDeLocation) {}
//await this.gaoDeLocation.getCurrentPosition.... 需要放在async 类型的方法里面
async loc1(){
/