angularjs - get geolocation ionic framework -
i'm working on application in many parts need user's current location. works me today have little problem. in home of application need information use same function use in application
function success(pos) { $scope.latitud = pos.coords.latitude $scope.longitud = pos.coords.longitude; } function error(err) { alert("el servicio de gps en tu dispositivo esta desactivado."); }; navigator.geolocation.getcurrentposition(success,error)
what need know data each time enter in view not it, try in many other parts of project use:
$scope.$on('$ionicview.enter', function(){ })
but not work, plus need when loading view or enter fully, action, occupies these geolocation data , connects server run.
$http({method: 'get', url: url_base+'viewscercanos/'+sessionservice.get("user_id")+'/'+sessionservice.get("hash")+"/"+$scope.latitud+"/"+$scope.longitud}) .success(function(data){ if(data.count > 0){ //solo tres $scope.views = data.view; $scope.mostrar_mensaje = false; }else{ $scope.mostrar_mensaje = true; $scope.mensaje = "no tienes views en tus registros." } }) .error(function(){ }) .finally(function(){ $scope.hide(); });
but @ time when action executed latitude , longitude values undefined after print run values , if seteados accordingly. order use in various parts of application , works fine, in particular case, guess may view main must more manage load these values before or during load .
Comments
Post a Comment