【发布时间】:2020-06-29 05:45:27
【问题描述】:
尝试在我的应用中添加地理定位功能时遇到问题。我正在使用https://ionicframework.com/docs/native/geolocation
在home.ts,在ionViewDidLoad()中调用这个findUserLocation():
import { Geolocation } from '@ionic-native/geolocation/ngx';
...
constructor(private geolocation: Geolocation) {}
ionViewDidLoad(){
this.findUserLocation()
}
findUserLocation(){
let options = {
enableHighAccuracy: true,
timeout: 25000
};
this.geolocation.getCurrentPosition(options).then((position) => {
this.location = {
latitude: position.coords.latitude,
longitude: position.coords.longitude
};
this.mapsProvider.init(this.location, this.mapElement);
}).catch((error) => {
console.log('Error getting location', error);
});
}
这是我的package.json
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
"@ionic-native/core": "4.20.0",
"@ionic-native/geolocation": "^5.22.0",
"@ionic-native/splash-screen": "4.20.0",
"@ionic-native/status-bar": "4.20.0",
"@ionic/storage": "2.2.0",
"cordova-plugin-geolocation": "^4.0.2",
"ionic-angular": "3.9.9",
"ionicons": "3.0.0",
"rxjs": "^6.3.3",
"rxjs-compat": "^6.3.3",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.29"
},
"devDependencies": {
"@ionic/app-scripts": "3.2.4",
"typescript": "2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-geolocation": {}
}
}
然后当我运行 ionic serve 时,控制台出现错误:
ERROR TypeError: Object(...) is not a function
at Geolocation.getCurrentPosition (index.js:10)
at HomePage.webpackJsonp.263.HomePage.findUserLocation (home.ts:45)
at HomePage.webpackJsonp.263.HomePage.ionViewDidLoad (home.ts:34)
at ViewController._lifecycle (view-controller.js:487)
at ViewController._didLoad (view-controller.js:370)
at NavControllerBase._didLoad (nav-controller-base.js:789)
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.js:4760)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
请帮忙解决。
【问题讨论】:
标签: google-maps ionic-framework geolocation