我正在尝试将地理定位功能(获取纬度和经度)放入库中并返回纬度和经度,因为在整个应用程序中都会调用坐标。我可以从controller.js 调用geo 库,lat 和long 显示在控制台中,但是如何在controller.js 调用函数中使用坐标呢?
在 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');
}
};
控制器.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;