cordovageolocationionic3

Ionic3 GPS enable


I am creating a application with Ionic 3, the full app based on location and map so I want to enable the GPS after starting the app so the app work smoothly.I have used native geolocation plugin.. it's solve the problem for Android lollipop but not working in other versions. I heard about the diagnosis plugin that can force the user to enable the GPS. Can anyone please tell me how can I do that, which work in both android and ios platform.


Solution

  • Location Accuracy

    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.

    You can install via following commands:

    $ ionic cordova plugin add cordova-plugin-request-location-accuracy
    $ npm install --save @ionic-native/location-accuracy
    

    Then must import in app.module.ts LocationAccuracy

    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)
        );
      }
    
    });
    

    And more detail then visit official link