getCurrentPosition crash


#1

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.


#2

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


#3

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.


#4

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