【问题标题】:Geolocation on iOS updates on standby ONLY with an active mapviewiOS 上的地理位置仅在使用活动地图视图的情况下更新待机
【发布时间】:2013-04-11 10:26:29
【问题描述】:

我已经尝试在 iOS 上计算地理位置已经有一段时间了,得出了一些奇怪的结论:

当应用程序打开时(不是处于待机状态或其他状态),地理位置非常准确。 当您将手机置于待机状态或最小化应用程序时,它会跳转到 AGPS,将位置更改为附近的 G 塔等。

但是;如果我在应用程序中有一个地图视图,并且每次触发事件时我都会更新用户位置,它似乎在待机和非待机状态下也能正常工作。 这个地图视图触发了什么,所以它会停留在普通 GPS 上而不是 AGPS 上?

这是地图视图的创建:

var mapview = Ti.Map.createView({
    bottom: -300,
    height: 200,
    mapType: Ti.Map.STANDARD_TYPE,
    region: {
        latitude: 0,
        longitude: 0, 
        latitudeDelta: delta,
        longitudeDelta: delta
    },
    animate:true,
    regionFit:true,
    userLocation:true
});

mainWindow.add(mapview);

以及位置处理:

//Set a timestamp on the current time. This is being checked later to see if its 5 minutes later(Because setInterval isn't trustworthy check will be done this way)
var realTime = new Date();
realTime = realTime.getTime();

//Set the battery time to be on the currenttime plus 5 minutes
batteryTimeToBe = realTime+batteryTimeIncrement;

//Empty interval and text to make a clean (re)start
clearInterval(interval);

//Set a half second timer on the stop button appearing(So people can't double tap the buttons)
stopTimeout = setTimeout(showStopButton, 1000);

//Switch the textlabels and buttons from startview to stopview
stopText.show();
startText.hide();
btnStart.hide();

//Locationhandler
location.start({ 
    action: function (e) {
        if (e.coords) {


            mapview.setLocation({
                latitude: e.coords.latitude,
                longitude: e.coords.longitude,
                animate: false,
                latitudeDelta: delta,
                longitudeDelta: delta
            });


            //If the newly acquired location is not the same as the last acquired it is allowed
            if (e.coords.longitude != lastLon && e.coords.latitude != lastLat) {
                //set the last acquired locations+other info to their variables so they can be checked(and used)
                lastLat = e.coords.latitude;
                lastLon = e.coords.longitude;

                lastKnownAltitude = e.coords.altitude;
                lastKnownHeading = e.coords.heading;
                lastKnownSpeed = e.coords.speed;

                if (lastLat != 0 && lastLon != 0) {
                    setGPSholder(lastLat, lastLon, lastKnownAltitude, lastKnownHeading, lastKnownSpeed);
                } else {
                    GPSSaved.text = 'Geen coordinaten.';
                }
            }
        }

        var timeNow = new Date();
        timeNow = timeNow.getTime();
        //If the now-time is higher or equal to the batteryTimeToBe(Which is reset after every call or when the start button is fired) send the batteryLevel
        if (timeNow >= batteryTimeToBe) {
            sendBatteryLevel();
            batteryTimeToBe = timeNow+batteryTimeIncrement;
            timeNow = null;
            //Ti.API.info(new Date());
        }

    }
});

/*
A second interval which shows a counter to the user and makes sure a location is sent
roughly every 5 seconds(setInterval isn't accurate though)
A lot of counters are tracked for several reasons:
    minuteInterval:     Counter which makes sure the last location is sent after a minute if no new one is found in the meantime
    secondsLastSent:    The visual counter showing the user how long its been for the last save(Is reset to 0 after a succesful save)
    */
interval = setInterval(function () {
    minuteInterval++;
    secondsLastSent++;

    counterBlock.text = "De laatste locatie is " + secondsLastSent + " seconden geleden verstuurd";

    //If the counter is higher than 5 send a new coordinate. If at the same time the minuteInterval is over a minute
    //The last location is put in the array before calling the sendCoordinates
    if (counter >= 5) {
        if (minuteInterval > 60) {
            if (lastLat != 0 && lastLon != 0) {
                setGPSholder(lastLat, lastLon, lastKnownAltitude, lastKnownHeading, lastKnownSpeed);
            }
        }
        counter = 1;
        sendCoordinates();
    } else {
        counter++;
    }
}, 1000);

【问题讨论】:

  • 地图视图很可能启用了 GPS。
  • 不能手动开启吗?
  • 如果是你的应用程序,那么你可以更改启用GPS的代码,可以。明确哪个应用,你说的是“应用”
  • 我正在构建的应用程序。不幸的是,我不能只在 iOS 应用程序中“启用 GPS”。它使用 GPS 或 AGPS。但我想知道我是否可以强制应用使用 GPS 而不是 AGPS 功能

标签: ios geolocation titanium titanium-mobile


【解决方案1】:

关于钛:

Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST; (or ACCURACY_HIGH)

钛中的位置有一个属性提供者,它的属性准确性可以很好也可以很正常。检查罚款。进一步检查提供者的名称

在 Titanium 中有自动定位和手动定位模式。使用手动模式并尝试是否可以将电池消耗设置为高,并将精度设置为高。 (GPS总是需要高电量,没有办法解决这个问题,没有低电量GPS)

【讨论】:

  • 我们还在谈论钛吗?
  • 检查是否有 location.getAccuracy 或水平精度
  • 啊,是的。手机进入待机状态时,这种准确性不会改变任何事情。只要按下待机按钮,它就会切换到 AGPS
  • 您是否允许您的应用在后台运行 GPS?在 plist 文件中?
  • 是的。所需的背景模式键。我有“应用程序与配件通信”和“应用程序注册位置更新”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-22
  • 1970-01-01
  • 2011-02-01
相关资源
最近更新 更多