Geolocation getCurrentPosition issue!


I’m trying to add geolocation to my app (ionic 3) to get my current position, but it gives me this error

import { Geolocation } from '@ionic-native/gelocation';

Expected 1-3 arguments, but got 0.

However, i get another error when using this import:

import { Geolocation } from '@ionic-native/gelocation/ngx';

Object(…) is not a function
at Geolocation.Array.concat.Geolocation.getCurrentPosition

my code:

import { Component } from '@angular/core';
import { Geolocation } from '@ionic-native/geolocation/ngx';
//import { Geolocation } from '@ionic-native/geolocation';

constructor( .... , private gps: Geolocation, .....) {}

    this.gps.getCurrentPosition().then(res => {

Thanks in advance!

1 Like

Has instalado el plugin?

$ ionic cordova plugin add cordova-plugin-geolocation --variable GEOLOCATION_USAGE_DESCRIPTION="To locate you"
$ npm install @ionic-native/geolocation@beta

yes, i installed the plugin of course

problem fixed with

ionic cordova plugin add cordova-plugin-geolocation
npm install --save @ionic-native/geolocation@4

looks like there was an issue with geo version

1 Like

I think it should be used as described here:

that is:


geolocationSuccess: The callback that is passed the current position.
geolocationError: (Optional) The callback that executes if an error occurs.
geolocationOptions: (Optional) The geolocation options.

Probably these instructions refer to an old version of the library: