这是我在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模拟器中运行此代码时,会弹出一个“位置当前不可用”。
这是否意味着我在移动设备上运行此代码(启用GPS)它不会给我任何GPS相关输出?或者它是我的代码的东西?
谢谢。
答案 0 :(得分:2)
如果您想在模拟器中运行地理位置服务,则必须以ddms设置纬度和经度。