4

我尝试了以下代码来找出用户在钛 android 中的位置

application.Ti.App.GeoApp = {};
Ti.Geolocation.preferredProvider = Titanium.Geolocation.PROVIDER_GPS;
Ti.Geolocation.purpose = "testing";
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = 10;
if( Titanium.Geolocation.locationServicesEnabled === false ) {
    Ti.API.debug('Your device has GPS turned off. Please turn it on.');
}
function updatePosition(e) {
    if( ! e.success || e.error ) {
    alert("Unable to get your location.");
    Ti.API.debug(JSON.stringify(e));
    Ti.API.debug(e);
    return;
    }
    Ti.App.fireEvent("app:got.location", {
    "coords" : e.coords
    });
};

Ti.App.addEventListener("app:got.location", function(d) {
    Ti.App.GeoApp.f_lng = d.longitude;
    Ti.App.GeoApp.f_lat = d.latitude;
    Ti.API.debug(JSON.stringify(d));
    Ti.Geolocation.removeEventListener('location', updatePosition);

    alert(JSON.stringify(d));
});
Titanium.Geolocation.getCurrentPosition( updatePosition );    
Titanium.Geolocation.addEventListener( 'location', updatePosition );

运行此代码后,它会发出警报 *无法获取您的位置。*在android模拟器中我缺少什么?提前致谢

4

1 回答 1

2

您必须使用 telnet 连接到您的模拟器并“设置位置”。每次设置位置时,您都会收到一个事件。

` telnet localhost 5554(考虑到有时端口不同 - 您可以在窗口标题栏中看到它)。

正在尝试 127.0.0.1...

连接到本地主机。

转义字符是 '^]'。

Android 控制台:键入“帮助”以获取命令列表

好的

geo fix 15.4548 12.4548(参数是经度,纬度,度数)

好的

退出`

享受

于 2011-09-27T06:22:07.570 回答