Skip to content

Instantly share code, notes, and snippets.

@andreaj8
Created July 26, 2013 09:24
Show Gist options
  • Save andreaj8/6087513 to your computer and use it in GitHub Desktop.
Save andreaj8/6087513 to your computer and use it in GitHub Desktop.
Geolocalizzation Titanium
//var Cloud = require('ti.cloud');
Titanium.Geolocation.purpose = "GPS user coordinates";
Titanium.Geolocation.distanceFilter = 2; // set the granularity of the location event
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
// Titanium.Geolocation.preferredProvider = Titanium.Geolocation.PROVIDER_GPS;
exports.position = function(functionOnSuccess,functionOnError){
locationAdded = false;
if (Titanium.Geolocation.locationServicesEnabled === false)
{
Titanium.UI.createAlertDialog({title:'IsoRadio - Errore GPS', message:L('error_gps')}).show();
functionOnError();
}
else{
Titanium.Geolocation.showCalibration = false;
Titanium.Geolocation.headingFilter = 90;
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = 5;
var locationCallback = function(e)
{
//alert("You move 10 M");
if (!e.success || e.error)
{
Ti.API.log('error:' + JSON.stringify(e.error));
Ti.API.log("Code translation: "+translateErrorCode(e.code));
functionOnError();
return;
}
var longitude = e.coords.longitude;
var latitude = e.coords.latitude;
var altitude = e.coords.altitude;
var heading = e.coords.heading;
var accuracy = e.coords.accuracy;
var speed = e.coords.speed;
var timestamp = e.coords.timestamp;
var altitudeAccuracy = e.coords.altitudeAccuracy;
if (locationAdded) {
Titanium.Geolocation.removeEventListener('location', locationCallback);
locationAdded = false;
functionOnSuccess(e.coords);
}else{
functionOnError();
}
}
Titanium.Geolocation.addEventListener('location', locationCallback);
locationAdded = true;
}// else
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment