Attempting to utilize Geolocation in ionic2 for device location access. Referred to the official documentation on https://ionicframework.com/docs/native/geolocation/. Successfully installed the necessary packages:
$ ionic plugin add cordova-plugin-geolocation $ npm install --save @ionic-native/geolocation
Listed below is the implemented code snippet.
import { Geolocation } from '@ionic-native/geolocation';
....
constructor(private placesService:PlacesService,private navCtrl:NavController,private geolocation:Geolocation) {
}
onLocateUser(){
this.geolocation.getCurrentPosition()
.then((location) => {
console.log('Location Fetched Successfully');
}).catch((error) => {
console.log('Error getting Location', error);
});
}
Moreover, this is how my package.json file appears:
{
"name": "ionic-hello-world",
"version": "0.0.0",
...
}
An encountered issue:
Typescript Error
Module '"D:/Ionic/ak-places/node_modules/@ionic-native/core/index"' has no exported member 'IonicNativePlugin'.
D:/Ionic/ak-places/node_modules/@ionic-native/geolocation/index.d.ts
import { IonicNativePlugin } from '@ionic-native/core';
import { Observable } from 'rxjs/Observable';