Skip to content

Instantly share code, notes, and snippets.

@manumaticx
Last active March 15, 2017 18:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save manumaticx/8436670 to your computer and use it in GitHub Desktop.
Save manumaticx/8436670 to your computer and use it in GitHub Desktop.
CommonJS location helper for Titanium
var location = require('location');
if (location.enabled){
if (location.hasAuth){
location.currentLocation(function(e){
alert(e.latitude + '; ' + e.longitude);
});
}else{
alert('need permission to access location service');
}
}else{
alert('enable location services');
}
//
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = .25;
Ti.Geolocation.purpose = L('location_purpose');
// PUBLIC FUNCTION
/**
* @param {Object} _callback call on completion of location query
*/
exports.currentLocation = function(_callback) {
Titanium.Geolocation.getCurrentPosition(function(e) {
if(e.error) {
Ti.API.error(JSON.stringify(e.error));
if(_callback) {
_callback(false);
}
return;
}
if(_callback) {
_callback(e.coords);
}
});
};
exports.enabled = function(){
return Ti.Geolocation.locationServicesEnabled;
};
exports.hasAuth = function(){
return Ti.Geolocation.getLocationServicesAuthorization() ===
Ti.Geolocation.AUTHORIZATION_AUTHORIZED;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment