Created
July 26, 2013 09:24
-
-
Save andreaj8/6087513 to your computer and use it in GitHub Desktop.
Geolocalizzation Titanium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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