Skip to content

Instantly share code, notes, and snippets.

@pietromalerba
Forked from gbaldera/app.js
Last active December 17, 2015 02:19
Show Gist options
  • Save pietromalerba/5534779 to your computer and use it in GitHub Desktop.
Save pietromalerba/5534779 to your computer and use it in GitHub Desktop.
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