getMyLocation crashes app when permission denied in ionic 2
See original GitHub issueI’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:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@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).
@Guchster Fixed.