Geolocation

Improve this doc

$ ionic plugin add cordova-plugin-geolocation

Repo: https://github.com/apache/cordova-plugin-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.

Usage

import {Geolocation} from 'ionic-native';



Geolocation.getCurrentPosition().then((resp) => {
 //resp.coords.latitude
 //resp.coords.longitude
})

let watch = Geolocation.watchPosition();
watch.subscribe((data) => {
 //data.coords.latitude
 //data.coords.longitude
})

Static Methods

getCurrentPosition(options)

Get the device’s current position.

Param Type Details
options GeolocationOptions

The geolocation options.

Returns: Returns a Promise that resolves with the position of the device, or rejects with an error.

watchPosition(options)

Watch the current device’s position. Clear the watch by unsubscribing from Observable changes.

var subscription = Geolocation.watchPosition().subscribe(position => {
  console.log(position.coords.longitude + ' ' + position.coords.latitude);
});

// To stop notifications
subscription.unsubscribe();
Param Type Details
options GeolocationOptions

The geolocation options.

Returns: Returns an Observable that notifies with the position of the device, or errors.

API

Native

General