Titanium Geolocation在Android模拟器中不起作用

时间:2013-01-03 20:16:03

标签: javascript titanium titanium-mobile

我收到此错误:

  

[ERROR] [GeolocationModule(278)](KrollRuntimeThread)[633,2564]无法获取当前位置,位置为空

我没有任何运气跟着别人的建议。

有人能引导我朝着正确的方向前进吗?我会非常感激的。谢谢!

var win1 = Titanium.UI.createWindow({
    title : 'map_landing',
    backgroundColor : '#fff'
});

var win2 = Titanium.UI.createWindow({
    title : 'hails_window',
    backgroundColor : '#fff'
});

var win3 = Titanium.UI.createWindow({
    title : 'cabs_window',
    backgroundColor : '#fff'
});

User = {
    location : {}
};

var hail_button = Titanium.UI.createButton({
    title : 'Hail Cab',
    top : 10,
    width : 200,
    height : 50
});

var find_button = Titanium.UI.createButton({
    title : 'Find People',
    bottom : 10,
    width : 200,
    height : 50
});

var options = {
    accessKeyId : '',
    secretAccessKey : ''
}

Ti.Geolocation.purpose = "Receive user location";

Titanium.Geolocation.getCurrentPosition(function(e) {
    if (e.error) {
        alert('HFL cannot get your current location');
        return;
    }

    User.location.longitude = e.coords.longitude;
    User.location.latitude = e.coords.latitude;
    User.location.accuracy = e.coords.accuracy;
    User.location.speed = e.coords.speed;
    User.location.timestamp = e.coords.timestamp;

    var mapview = Titanium.Map.createView({
        mapType : Titanium.Map.STANDARD_TYPE,
        region : {
            latitude : User.location.latitude,
            longitude : User.location.longitude,
            latitudeDelta : 0.01,
            longitudeDelta : 0.01
        },
        animate : true,
        regionFit : true,
        userLocation : true
    });

    win1.add(mapview);
    win1.add(hail_button);
    win1.add(find_button);
    hail_button.addEventListener('click', function(e) {
        alert('hello');
        $.ajax('http://hail.pagodabox.com/add_hail', {
            type : 'POST',
            lat : User.location.latitude,
            lang : User.location.longitude,
            success : function(response) {
                alert(response)
            }
        })
    });

    find_button.addEventListener('click', function(e) {

    });
    win1.open();
});

1 个答案:

答案 0 :(得分:1)

我花了一些时间来追踪这一点,但我想我已经找到了“修复”Android模拟器中缺少位置所需的步骤(来自this answer):

  

首先,打开ddms(Dalvik Debug Monitor)。在Windows上,导航到   android-sdk \ tools目录并运行ddms.bat。第一行   左上方的窗格将读取类似“模拟器 - ####”的内容,例如   模拟器-5560。

     

打开命令提示符窗口。输入'telnet localhost ####'   替换上面找到的数字。这将打开一个telnet   窗口到你的android模拟器。

     

输入以下命令(替换您自己的经度和纬度,   按顺序,如果你愿意):

     

geo fix -82.411629 28.054553

     

(我很确定你可以将高程添加为第三个数字。)GPS   图标将出现在模拟器的通知栏中。地理位置是   现在可用。此时,我可以在我的应用中获取位置数据   在其他应用中,例如地图。