Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created April 13, 2012 22:19
Show Gist options
  • Save pec1985/2380495 to your computer and use it in GitHub Desktop.
Save pec1985/2380495 to your computer and use it in GitHub Desktop.
GetLocation
function GetLocation(callback){
if (!Ti.Network.online)
{
callback({success: false});
return;
}
var PROVIDER = Titanium.Geolocation.PROVIDER_GPS;
var timeout;
(function getLocation(){
function printLocation(e){
clearTimeout(timeout);
callback(e);
Ti.Geolocation.removeEventListener('location', printLocation);
}
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Ti.Geolocation.preferredProvider = PROVIDER;
Ti.Geolocation.addEventListener('location', printLocation);
timeout = setTimeout(function(){
Ti.Geolocation.removeEventListener('location', printLocation);
PROVIDER = Titanium.Geolocation.PROVIDER_NETWORK;
getLocation();
},1500);
})();
}
GetLocation(function(e){alert(e);});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment