i am trying to get the GPS location of a user for all my services i have created a separated file let Say Factory.js
This is the code in my factory file:
var get_my_location=function(){
var onSuccess = function(position) {
if(typeof position ==='object'){
return position
}
else{
return 500;
}
};
// onError Callback receives a PositionError object
//
function onError(error) {
return {"err":error}
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
i want to call and get the position in response when any other function calls this get_my_location();
When i am trying like:
var resp=get_my_location();
console.log(resp) //outpur 'undefined'
obviously it should give undefined,how can i apply a callback so that i may get the position in resp as a returned value.