我已经尝试在iOS上解决地理位置已经有一段时间了,并得出了一些奇怪的结论:
当应用程序处于打开状态(非待机状态或其他状态)时,地理定位非常准确。 当您将手机置于待机状态或最小化应用程序时,它会跳转到AGPS,将位置更改为靠近G-tower等。
然而;如果我在应用程序中有一个mapview并且我每次触发事件时都更新用户位置,它似乎在待机状态下工作为非待机状态。 这个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);
答案 0 :(得分:0)
on Titanium:
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST; (or ACCURACY_HIGH)
钛中的位置有一个属性提供程序,它具有精确或过程的属性准确性。检查罚款。进一步检查提供者名称
在Titanium中有位置自动和手动模式。使用手动模式,如果您可以将电池消耗设置为高电平,并将精度设置为高电平,请尝试使用。 (GPS总是需要高电量,没有办法绕过这个,没有低电池GPS)