我想把地理位置功能(获取纬度和经度)放入一个库并返回经度和纬度,因为在整个应用程序中调用坐标。我可以从controller.js调用geo库,lat和long显示在控制台中,但是如何在controller.js的调用函数中使用坐标?如何将库中的变量传递给Appcelerator/Titanium中的控制器?
在app/LIB/geo.js
exports.getLongLat = function checkLocation(){
if (Ti.Geolocation.locationServicesEnabled) {
Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.error) {
Ti.API.error('Error: ' + e.error);
} else {
Ti.API.info(e.coords);
var latitude = e.coords.latitude;
var longitude = e.coords.longitude;
console.log("lat: " + latitude + " long: " + longitude);
}
});
} else {
console.log('location not enabled');
}
};
controller.js
geolocation.getLongLat(); //this calls the library, but I don't know how I can get the coordinates "back" into the controller.js file for using it in the var args below.
var args ="?display_id=check_if_in_dp_mobile&args[0]=" + lat + "," + lon;
非常感谢亚当明确的解释。特别是“基本上移动那个内容......”的部分。这是我没有得到的最后一个缺失部分。 – user24957