Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Location Accuracy

Improve this doc

This Cordova/Phonegap plugin for Android and iOS to request enabling/changing of Location Services by triggering a native dialog from within the app, avoiding the need for the user to leave your app to change location settings manually.

Repo: https://github.com/dpa99c/cordova-plugin-request-location-accuracy

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-request-location-accuracy
    $ npm install --save @ionic-native/location-accuracy@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { LocationAccuracy } from '@ionic-native/location-accuracy';

constructor(private locationAccuracy: LocationAccuracy) { }

...

this.locationAccuracy.canRequest().then((canRequest: boolean) => {

  if(canRequest) {
    // the accuracy option will be ignored by iOS
    this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY).then(
      () => console.log('Request successful'),
      error => console.log('Error requesting location permissions', error)
    );
  }

});

Instance Members

canRequest()

Indicates if you can request accurate location

Returns: Promise<boolean> Returns a promise that resovles with a boolean that indicates if you can request accurate location

isRequesting()

Indicates if a request is currently in progress

Returns: Promise<boolean> Returns a promise that resolves with a boolean that indicates if a request is currently in progress

request(accuracy)

Requests accurate location

Param Type Details
accuracy number

Accuracy, from 0 to 4. You can use the static properties of this class that start with REQUESTPRIORITY

Returns: Promise<any> Returns a promise that resolves on success and rejects if an error occurred

REQUEST_PRIORITY_NO_POWER

Convenience constant

REQUEST_PRIORITY_LOW_POWER

Convenience constant

REQUEST_PRIORITY_BALANCED_POWER_ACCURACY

Convenience constant

REQUEST_PRIORITY_HIGH_ACCURACY

Convenience constant

SUCCESS_SETTINGS_SATISFIED

Convenience constant

SUCCESS_USER_AGREED

Convenience constant

ERROR_ALREADY_REQUESTING

Convenience constant

ERROR_INVALID_ACTION

Convenience constant

ERROR_INVALID_ACCURACY

Convenience constant

ERROR_EXCEPTION

Convenience constant

ERROR_CANNOT_CHANGE_ACCURACY

Convenience constant

ERROR_USER_DISAGREED

Convenience constant

ERROR_GOOGLE_API_CONNECTION_FAILED

Convenience constant

API

Native

General