У меня проблемы при попытке добавить функцию геолокации в мое приложение. Я использую https://ionicframework.com/docs/native/geolocation
В home.ts
, вызовите функцию findUserLocation () в ionViewDidLoad ():
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": {}
}
}
А потом, когда я запускаю ioni c 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)
Пожалуйста, помогите для решения.