android - Titanium.Geolocation.getCurrentPosition() 不给出输出

标签 android titanium appcelerator appcelerator-mobile

这是我在 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 相关输出?还是我的代码有问题?
谢谢。

最佳答案

如果您想在模拟器中运行地理位置服务,则必须在 ddms 中设置纬度和经度。

关于android - Titanium.Geolocation.getCurrentPosition() 不给出输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11607429/

相关文章:

android - 系统找不到指定的文件 "classes.dex"

安卓+Admob : Error: String types not allowed (at 'configChanges' with value(etc. ..)

java - 改造不适用于特定版本的 android

android - 如何在运行时android期间获取堆栈跟踪

android - Firebase 分析刷新率

android - 为钛移动开发禁用双击缩放 WebView

java - 从另一个 Fragment 获取值,然后将 Items 添加到自定义 recyclerview

钛 JS : cannot use an image stored in SQLite Database in TiSocial module

android - Titanium Appcelerator 安卓模块 : How to create a proxy?

python - Mac 上的 Titanium 桌面构建