简体   繁体   English

Titanium地理位置无法在Android模拟器中使用

[英]Titanium Geolocation Not Working in Android Emulator

I get this error: 我收到此错误:

[ERROR][GeolocationModule( 278)] (KrollRuntimeThread) [633,2564] Unable to get current position, location is null [错误] [GeolocationModule(278)](KrollRuntimeThread)[633,2564]无法获取当前位置,位置为null

and I have followed other people's advice without any luck. 我听从别人的建议,没有任何运气。

Could someone lead me in the right direction? 有人可以引导我朝正确的方向前进吗? I would be so grateful. 我将非常感激。 Thank you! 谢谢!

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();
});

It took me some time to track this down, but I think I've found the steps needed to "fix" the lack of a location in the Android emulator (from this answer ): 我花了一些时间来跟踪它,但是我想我已经找到了“修复” Android仿真器中位置不足所需的步骤(来自此答案 ):

First, open ddms (Dalvik Debug Monitor). 首先,打开ddms(Dalvik调试监视器)。 On Windows, navigate to the android-sdk\\tools directory and run ddms.bat. 在Windows上,导航至android-sdk \\ tools目录并运行ddms.bat。 The first line in the top-left pane will read something like "emulator-####" such as emulator-5560. 左上方窗格的第一行将显示类似“ emulator-####”的内容,例如emulator-5560。

Open a command prompt window. 打开命令提示符窗口。 Enter 'telnet localhost ####' substituting the number you found above. 输入“ telnet localhost ####”替换上面找到的数字。 This will open a telnet window to your android emulator. 这将打开一个telnet窗口到您的android模拟器。

Enter the following command (substitute your own longitude & latitude, in that order, if you'd like): 输入以下命令(如果需要,请依次替换您自己的经度和纬度):

geo fix -82.411629 28.054553

(I'm pretty sure you can add elevation as a third number.) The GPS icon will appear in the emulator's notification bar. (我很确定您可以将海拔高度添加为第三个数字。)GPS图标将出现在模拟器的通知栏中。 Geolocation is now available. 现在可以使用地理位置。 At this point, I could get location data in my app and in other apps, such as Maps. 此时,我可以在我的应用程序和其他应用程序(例如地图)中获取位置数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM