question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getMyLocation crashes app when permission denied in ionic 2

See original GitHub issue

I’m submitting a … [ ] question [ x ] any problem or bug report [ ] feature request

The plugin version: [ ] 1.4.x [ x ] 2.0.0-beta3

If you choose ‘problem or bug report’, please select OS: [x ] Android [ ] iOS

cordova information: (run $> cordova plugin list)

com.googlemaps.ios 2.2.0 "Google Maps SDK for iOS"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-googlemaps 2.0.0-beta3-20170816-1440 "cordova-plugin-googlemaps"
cordova-plugin-googleplus 5.1.1 "Google SignIn"
cordova-plugin-facebook4 1.7.4 "Facebook Connect"
...

Current behavior: First of all, great work! this plugin is awesome!

Problem: The map is working fine, the problem comes when I use the getMyLocation() method and the user denies the permission (either access to device location permission or activate location permission), in this cases the app crashes most of the time (not every time). I am not using ionic-native.

My Environment:

  • Ionic 2
  • Android 6.0.1
  • Using the master branch of this plugin

Expected behavior: The method should go to the onError function every time (when permission is denied) and not crash.

Steps to reproduce:

Install the plugin Call the map.getMyLocation() method Deny request for permissions when asked in app

Related code:

//I am sure that the mapCenter is a valid LatLng object

  map: any;

  private loadMap(mapCenter: LatLng) {
    this.platform.ready().then(() => {
      let element = document.getElementById('map');
      this.map = (<any>window).plugin.google.maps.Map.getMap(element, this.getMapConfigurations(mapCenter));
      this.map.on((<any>window).plugin.google.maps.event.MAP_READY, map => {
        console.log("Loaded map! (working fine)");
        var onSuccess = function (location) {
          console.log("I want to get here if success (working fine)");
        };
        var onError = function (msg) {
         // PROBLEM: can't get here when persmission denied //
          console.log("I want to get here if error (working sometimes)");
        };
        this.map.getMyLocation(onSuccess, onError);
      });
    }

  private getMapConfigurations(mapCenter: LatLng) {
    return {
      'backgroundColor': 'white',
      'controls': {
        'compass': true,
        'myLocationButton': true,
        'indoorPicker': true,
        'zoom': true
      },
      'gestures': {
        'scroll': true,
        'tilt': true,
        'rotate': true,
        'zoom': true
      },
      'camera': {
        'latLng': mapCenter,
        'tilt': 10,
        'zoom': 15,
        'bearing': 15
      }
    }
  }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
santiagommejiacommented, Aug 25, 2017

@wf9a5m75 Thanks! The first permission (access to device location) is working great. However the second permission (allow your device to enable location) still crashes app when denied, it only asks for this permission if your location is turned off (the permission asks to turn the device location on).

0reactions
wf9a5m75commented, Aug 25, 2017

@Guchster Fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Permission denial causing app crash in Ionic - Stack Overflow
I have been confused by a random crash in my app since I updated to cordova 5 and started using crosswalk. This is...
Read more >
Ionic 4 - Android 9 - App crash on permission requests
Basically whenever a pop-up that is not part of the ionic app needs to come on screen, the app crashes, without any log...
Read more >
Ionic 5 Complete guide on Geolocation, permission and auto ...
Learn how to implement geolocation, permissions and auto turn-on GPS in Ionic apps in Cordova or Capacitor, Angular or React.
Read more >
cordova-plugin-googlemaps - npm
Cordova GoogleMaps plugin for Android, iOS and Browser v2.7.1 ... This plugin displays Google Maps in your application.
Read more >
Capacitor 3.3.2 - File permission issues crashing app : r/ionic
Upon applying the selected camera photo or the imported photo library photo, the app crashes and gives the error below. Also below is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found