Reputation: 87
I'm trying to access the device location using Geolocation in ionic2. Followed the ionic2 documentation here https://ionicframework.com/docs/native/geolocation/ . Added the packages
$ ionic plugin add cordova-plugin-geolocation $ npm install --save @ionic-native/geolocation
Below is my code.
import { Geolocation } from '@ionic-native/geolocation';
....
constructor(private placesService:PlacesService,private navCtrl:NavController,private geolocation:Geolocation) {
}
....
onLocateUser(){
this.geolocation.getCurrentPosition()
.then((locaton) => {
console.log('Location Fetched Successfully');
}).catch((eroor) => {
console.log('Error getting Location',eroor);
});
}
And my package.json looks like as below
{
"name": "ionic-hello-world",
"version": "0.0.0",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "4.0.0",
"@angular/compiler": "4.0.0",
"@angular/compiler-cli": "4.0.0",
"@angular/core": "4.0.0",
"@angular/forms": "4.0.0",
"@angular/http": "4.0.0",
"@angular/platform-browser": "4.0.0",
"@angular/platform-browser-dynamic": "4.0.0",
"@ionic-native/core": "3.4.2",
"@ionic-native/geolocation": "^3.6.1",
"@ionic-native/splash-screen": "3.4.2",
"@ionic-native/status-bar": "3.4.2",
"@ionic/storage": "^2.0.0",
"ionic-angular": "3.0.1",
"ionic-native": "^3.5.0",
"ionicons": "3.0.0",
"rxjs": "5.1.1",
"sw-toolbox": "3.4.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@ionic/app-scripts": "1.3.0",
"typescript": "~2.2.1"
},
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"ionic-plugin-keyboard",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen"
],
"cordovaPlatforms": [],
"description": "ak-places: An Ionic project"
}
I'm getting the following error
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';
Upvotes: 1
Views: 313
Reputation: 87
Finally its solved my issue https://stackoverflow.com/a/43659149/5350407 . Changed ionic core version in package.json and then executed npm install
command
Upvotes: 0
Reputation: 65860
You need to remove "ionic-native": "^3.5.0",
from your package.json
and use latest "@ionic-native/core": "3.5.0",
.After that run npm i
.
Here is the official package.json file.
Hope you know how to implement native plugins as a provider.If you want, you can read more from official doc here.
Upvotes: 1