Skip to content

Instantly share code, notes, and snippets.

@dawsontoth
Created February 9, 2011 23:35
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dawsontoth/819581 to your computer and use it in GitHub Desktop.
Save dawsontoth/819581 to your computer and use it in GitHub Desktop.
Constantly Updating Geolocation in Appcelerator Titanium
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = 0;
var win = Ti.UI.createWindow({backgroundColor: '#fff'});
var label = Ti.UI.createLabel();
win.add(label);
win.open();
function reportPosition(e) {
if (!e.success || e.error) {
label.text = 'error: ' + JSON.stringify(e.error);
}
else {
var accuracy = e.coords.accuracy;
var timestamp = e.coords.timestamp;
label.text = 'geo time: ' + new Date(timestamp) + ', accuracy: ' + accuracy;
}
}
// this fires once
Titanium.Geolocation.getCurrentPosition(reportPosition);
// this fires whenever the distance filter is surpassed
Titanium.Geolocation.addEventListener('location', reportPosition);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment