Last active
March 15, 2017 18:41
-
-
Save manumaticx/8436670 to your computer and use it in GitHub Desktop.
CommonJS location helper for Titanium
This file contains hidden or 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 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'); | |
} |
This file contains hidden or 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
// | |
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