0

I've tried to work out the geolocation on the iOS for quite some time now and came to some weird conclusions:

When the app is open(not on standby or whatever) the geolocation is very accurate. The moment you put your phone in standby or minimize the app it jumps to AGPS changing the locations to G-towers etc. closeby.

However; If i have a mapview in the app and i update the userlocation every time the event is triggered it seems to work aswell in standby as non-standby. What is this mapview triggering so it will stay on the normal GPS and not on AGPS?

Here's the creation of the mapview:

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

And the location handling:

//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);
4

1 回答 1

0

关于钛:

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

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

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

于 2013-04-15T09:13:20.940 回答