• Version 5.36.0
  • Published
  • 44.9 kB
  • 1 dependency
  • MIT license


npm i @ionic-native/geolocation
yarn add @ionic-native/geolocation
pnpm add @ionic-native/geolocation


Ionic Native - Native plugins for ionic apps



variable Geolocation

const Geolocation: GeolocationOriginal;


    class GeolocationOriginal

    class GeolocationOriginal extends IonicNativePlugin {}
    • Geolocation geolocation This plugin provides information about the device's location, such as latitude and longitude. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs.

      This API is based on the W3C Geolocation API Specification, and only executes on devices that don't already provide an implementation.

      For iOS you have to add this configuration to your configuration.xml file

      <edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
      <string>We use your location for full functionality of certain app features.</string>

      import { Geolocation } from '@ionic-native/geolocation/ngx';
      constructor(private geolocation: Geolocation) {}
      this.geolocation.getCurrentPosition().then((resp) => {
      // resp.coords.latitude
      // resp.coords.longitude
      }).catch((error) => {
      console.log('Error getting location', error);
      let watch = this.geolocation.watchPosition();
      watch.subscribe((data) => {
      // data can be a set of coordinates, or an error (if an error occurred).
      // data.coords.latitude
      // data.coords.longitude

      Coordinates Geoposition PositionError GeolocationOptions

    method getCurrentPosition

    getCurrentPosition: (options?: GeolocationOptions) => Promise<Geoposition>;
    • Get the device's current position.

      Parameter options

      The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).


      {Promise} Returns a Promise that resolves with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or rejects with an error.

    method watchPosition

    watchPosition: (
    options?: GeolocationOptions
    ) => Observable<Geoposition | PositionError>;
    • Watch the current device's position. Clear the watch by unsubscribing from Observable changes.

      const subscription = this.geolocation.watchPosition()
      .filter((p) => p.coords !== undefined) //Filter Out Errors
      .subscribe(position => {
      console.log(position.coords.longitude + ' ' + position.coords.latitude);
      // To stop notifications

      Parameter options

      The [geolocation options](https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions).


      {Observable<Geoposition | PositionError>} Returns an Observable that notifies with the [position](https://developer.mozilla.org/en-US/docs/Web/API/Position) of the device, or errors.


    interface Coordinates

    interface Coordinates {}

      property accuracy

      accuracy: number;
      • A double representing the accuracy of the latitude and longitude properties, expressed in meters.

      property altitude

      altitude: number;
      • A double representing the position's altitude in metres, relative to sea level. This value can be null if the implementation cannot provide the data.

      property altitudeAccuracy

      altitudeAccuracy: number;
      • A double representing the accuracy of the altitude expressed in meters. This value can be null.

      property heading

      heading: number;
      • A double representing the direction in which the device is traveling. This value, specified in degrees, indicates how far off from heading true north the device is. 0 degrees represents true north, and the direction is determined clockwise (which means that east is 90 degrees and west is 270 degrees). If speed is 0, heading is NaN. If the device is unable to provide heading information, this value is null.

      property latitude

      latitude: number;
      • a double representing the position's latitude in decimal degrees.

      property longitude

      longitude: number;
      • A double representing the position's longitude in decimal degrees.

      property speed

      speed: number;
      • A double representing the velocity of the device in meters per second. This value can be null.

      interface GeolocationOptions

      interface GeolocationOptions {}

        property enableHighAccuracy

        enableHighAccuracy?: boolean;
        • Indicates the application would like to receive the best possible results. If true and if the device is able to provide a more accurate position, it will do so. Note that this can result in slower response times or increased power consumption (with a GPS chip on a mobile device for example). On the other hand, if false, the device can take the liberty to save resources by responding more quickly and/or using less power. Default: false. {boolean}

        property maximumAge

        maximumAge?: number;
        • Is a positive long value indicating the maximum age in milliseconds of a possible cached position that is acceptable to return. If set to 0, it means that the device cannot use a cached position and must attempt to retrieve the real current position. If set to Infinity the device must return a cached position regardless of its age. Default: 0.

        property timeout

        timeout?: number;
        • Is a positive long value representing the maximum length of time (in milliseconds) the device is allowed to take in order to return a position. The default value is Infinity, meaning that getCurrentPosition() won't return until the position is available.

        interface Geoposition

        interface Geoposition {}

          property coords

          coords: Coordinates;
          • A Coordinates object defining the current location

          property timestamp

          timestamp: number;
          • A timestamp representing the time at which the location was retrieved.

          interface PositionError

          interface PositionError {}

            property code

            code: number;
            • A code that indicates the error that occurred

            property message

            message: string;
            • A message that can describe the error that occurred

            Package Files (1)

            Dependencies (1)

            Dev Dependencies (0)

            No dev dependencies.

            Peer Dependencies (2)


            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@ionic-native/geolocation.

            • Markdown
            • HTML
              <a href="https://www.jsdocs.io/package/@ionic-native/geolocation"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>