GPS Confirmation pop up is Not Shown, why?


#1

hi,

i use the NG-cordova Geolocation plugin. The Gps work fine and also the error event is caught gr8, BUT i want that if the user dont have the GPS enable so the GPS service confirmation pop up will shown and the user can click on the settings and redirect to the setting of the device.

The problem is that the pop up confirmation is NOT shown :(, why?

i use One plus and Nexus 5 and Nexus 10 in all device is not work.

please advise :smile:


#2

This is not possible for an hybrid app. Native apps can go to the locationManager which is not available to Cordova.


#3

have you tried using this cordova plugin ?

https://github.com/mablack/cordova-diagnostic-plugin


#4

This plugin checks if GPS is enabled or not, but it does not show a popup with a link to directly route the the settings to enable it right?


#5

The diagnostic plugin has the “switchToLocationSettings” function which does what you want.

if (window.cordova) {
cordova.plugins.diagnostic.isLocationEnabled(
                    function(e) {
                        if (e)
                            successFunctionCall();
                        else {
                          // here you are
                          cordova.plugins.diagnostic.switchToLocationSettings();

                        }
                    },
                    function(e) {
                        alert('Error ' + e);
                    }
                );
            }

Please note, this plugin works only on device, not browser.


#6

First of all thanks!

second, i use another plugin that user is recommended ant it work fine.

as far as i understand Apple (IOS Devices) is not supported right?


#7

Tried out the method above and it works, but i want to open up google maps in the inappbrowser with the users location.

Here is what i have so far:
html:

<ion-nav-buttons side="right">
  <a ng-href="#" ng-click="getLocation();" class="button button-icon button-clear ion-navigate">
  </a>
</ion-nav-buttons>

controller.js:

$scope.checkLocation = function(){
  if (window.cordova) {
  cordova.plugins.diagnostic.isLocationEnabled(
                function(e) {
                    if (e){
                      successFunctionCall();
                    }   
                    else {
                      alert("Location Not Turned ON");
                      cordova.plugins.diagnostic.switchToLocationSettings();
                    }
                },
                function(e) {
                    alert('Error ' + e);
                }
            );
        }
}
$scope.getLocation = function(){
    $scope.checkLocation();
    $scope.supportsGeo = $window.navigator;
    $scope.position = null;
    $window.navigator.geolocation.getCurrentPosition(function(position) {
                $scope.$apply(function() {
                    $scope.position = position;
                    var link = "http://maps.google.com/maps?saddr="+$scope.position.coords.latitude+","+$scope.position.coords.longitude+"&daddr="+$scope.address;

                    $window.open(encodeURI(link), '_blank', 'location=no');
                });
              }, function(error) {
                  alert(error);
              },{enableHighAccuracy: true});
    
    }

The weird part is that it works in bluestacks but not in my HTC One M7(5.0.2). Because when you go back from location settings to the app, its like nothing happened. And when the button is clicked again nothing happens.

Any help would be greatly appreciated. Thanks!

PS: I just started out with Ionic just last week.