我想把地理位置功能(獲取緯度和經度)放入一個庫並返回經度和緯度,因爲在整個應用程序中調用座標。我可以從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