我試過現在制定出在iOS地理位置相當長的一段時間,並得出了一些結論怪異:地理位置上處於待機狀態的iOS更新,只能用積極的MapView
當應用程序打開時(不待機或其他)地理位置非常準確。 當您將手機置於待機狀態或將應用程序最小化時,它會跳轉至AGPS,將位置更改爲G-Tester等。
但是;如果我在應用程序中有一個mapview,並且每次觸發事件時都更新userlocation,它似乎可以在非待機狀態下工作。 這個mapview觸發是什麼,所以它會留在普通的GPS而不是AGPS上?
這裏的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);
和定位處理:
//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。 – AlexWien 2013-04-11 23:25:57
我無法手動啓用它嗎? – CaptainCarl 2013-04-12 06:34:01
如果它是您的應用程序,那麼您可以更改啓用GPS的代碼,是的。澄清哪個應用程序,你說「應用程序」 – AlexWien 2013-04-12 16:19:10