这是我在 Titanium Appcelerator 上的代码:
function ApplicationWindow(title) {
var self = Ti.UI.createWindow({
title:title,
backgroundColor:'white'
});
var button = Ti.UI.createButton({
height:44,
width:200,
title:L('openWindow'),
top:200
});
self.add(button);
function getPosition() {
alert("In the Function");
Titanium.Geolocation.getCurrentPosition(function(e) {
Titanium.Geolocation.distanceFilter = 10;
Ti.Geolocation.preferredProvider = "gps";
if (e.error) {
Ti.UI.createAlertDialog({
title: L('geolocate_failure'),
message: e.error
}).show();
return;
}
var found = new Object();
locateIndicator.show();
found.longitude = e.coords.longitude;
found.latitude = e.coords.latitude;
found.altitude = e.coords.altitude;
found.heading = e.coords.heading;
found.accuracy = e.coords.accuracy;
found.speed = e.coords.speed;
found.timestamp = e.coords.timestamp;
found.altitudeAccuracy = e.coords.altitudeAccuracy;
return found
});
}
button.addEventListener('click', function() {
alert("button click");
getPosition();
});
return self;
};
module.exports = ApplicationWindow;
当我在 Android Emulator 中运行此代码时,它会弹出“位置当前不可用”。这是否意味着直到我在移动设备上运行此代码(启用 GPS)它不会给我任何 GPS 相关的输出?还是与我的代码有关?
谢谢你。