getCurrentPosition crash

Hi guys,
this is my snippet

navigator.geolocation.getCurrentPosition(function (position) {

          $scope.position = position;
          console.log($scope.position);

        }); // getCurrentPosition()

When I start my android app, it’s asking for permission. I agree and the app is crashing. Same with the cordova plugin. Any suggestions?
By the way: The browser gives me the coordinates.

1 Like

use code like this to see problem

if (window.Connection) {

            if (navigator.connection.type == Connection.NONE) {

                $ionicPopup.confirm({

                    title: "Internet is not working",

                    content: "Internet is not working on your device."

                });

            }

        }

explore more this url , may be helpful.

http://www.codeandyou.com/2015/07/how-to-check-network-connection-in.html

I’m having the same issue, and is not because to a resource not yet loaded as suggest @virender.
Looks like the app asks for geolocation permission, and when i grant the permission, the app crashes.

Maybe it’s helping you. I wrote a factory for this problem and it worked!

My factory

var googleMapsService = function($q, $cordovaGeolocation) {

	// Variable, etc.
	var factory = {};
	var deferred = $q.defer();
	var position = {};
	var posOptions = {timeout: 10000, enableHighAccuracy: false};

  // Ermittlung der Smartphone Position
  factory.getCurrentPosition = function() {
    $cordovaGeolocation
      .getCurrentPosition(posOptions)
      .then(function(position) {
      	deferred.resolve(position);
      }, function(err) {
        // error
      });
      return deferred.promise;
  }

	return factory;
};

My controller

googleMapsService.getCurrentPosition()
    .then(function(position) {
      $rootScope.position = position;
    });