I'm working on an application in many parts I need to get the user's current location. This works especially well for me but today I have a little problem. In the home of my application I also need to get this information so that you use the same function that I use in my 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 I need is to know that data each time you enter in this view but I could not do it, try as in many other parts of my project use:
$scope.$on('$ionicView.enter', function(){
})
But it does not work, plus I need you when loading the view or enter it fully, an action, which occupies these geolocation data and connects to my server to 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 at the time when the action is executed the latitude and longitude values are undefined after print run values and if they are seteados accordingly. This order I use it in various parts of my application and everything works fine, but in this particular case, I guess may be that the view is the main must be something more to manage to load these values before or during load .