[TIMOB-24535] iOS: Ti.Geolocation Speed returning incorrect number or -1 for speed, requires docs-clarification
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-05-07T13:32:37.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.1.0 |
Components | iOS |
Labels | n/a |
Reporter | Amanda |
Assignee | Hans Knöchel |
Created | 2017-03-26T15:49:07.000+0000 |
Updated | 2017-05-09T17:40:42.000+0000 |
Description
When listening for the location event for iOS, the speed returned is very often -1 and sometimes an incorrect value. It's very inconsistent. This was working before with our previous app release with SDK 5.5.0.GA but it no longer does with the newest SDK 6.0.2. I also tried rolling back to 5.5.0.GA but this doesn't seem to fix the issue either.
index.js:
var numOfCalls = 0;
var locationCallback = function(e) {
$.numOfLocationCalls.text = "Num of calls: " + numOfCalls;
numOfCalls++;
if (!e.success || e.error) {
$.labelSpeed.text = "Error:" + JSON.stringify(e);
} else {
var mph = e.coords.speed * 2.23694;
$.label.text = "Speed: " + mph;
var overSpeed = (e.coords.speed > 5) ? true : false;
$.labelSpeed.text = "Over speed: " + overSpeed;
}
};
Ti.Geolocation.addEventListener('location', locationCallback);
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
Ti.Geolocation.distanceFilter = 5;
$.index.open();
index.xml:
<Alloy>
<Window class="container">
<View layout="vertical" height="Titanium.UI.SIZE">
<Label id="label">Hello, World</Label>
<Label id="labelSpeed">Hello, World</Label>
<Label id="numOfLocationCalls">Hello, World</Label>
</View>
</Window>
</Alloy>
in tiapp.xml, I have these permissions:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your location will only be used when the app is running.</string>
NOTE: I tried adding this to the axway support portal as I am a enterprise developer, but I can't seem to login at the moment. Will likely be adding this there once I get that sorted out.
I forgot to mention - this seems to work perfectly in the simulator when changing the location type in the debug menu. The issue occurs when driving and using an actual device. There is also a stackoverflow question on this here: http://stackoverflow.com/questions/42615548/appcelerator-geolocation-never-returns-a-speed-on-ios
Hey Amanda! Maybe it is an iOS issue? Especially if it worked with 5.5.0 but does not when using 5.5.0 now. We did not change Geolocation-related API's between those versions. We will take a look
I forgot to remove the onClick event for the label in index.xml, sorry about that. It might be that iOS did change something in relation to this. Testing with hyper loop, it seems that for the core location accuracy ( CLLocationAccuracy ) , the most consistent value has been kCLLocationAccuracyBestForNavigation. And we've been using Ti.Geolocation.ACCURACY_BEST, I'm guessing maps to kCLLocationAccuracyBest. We ended up testing it again with Ti.Geolocation.ACCURACY_BEST_FOR_NAVIGATION accuracy, and it finally seems to be working again as expected. Can this be updated in the documentation somewhere?
Ti.Geolocation.ACCURACY_BEST does not work any more. It is used to as it is indicated here but it no longer is. Please address this issue. We are substituting ACCURACY_BEST_FOR_NAVIGATION as a workaround.
Checking this issue.
subtle changes to the sample code: add
$.index.open
to index.js removeonClick="doClick"
from index.xmlI see the same issue when using Ti.Geolocation.ACCURACY_BEST, using: MacOS 10.12 (16A323) Studio 4.8.1.201612050850 Ti SDK 6.0.4.GA Appc NPM 4.2.9 Appc CLI 6.2.0 Alloy 1.9.11 Xcode 8.3.2 (8E2002) I will get a -1 for the coords.speed value. In the couple hours I was testing it, I did not see the negative value while driving, but I would see it when I stopped (not consistently though). After changing the accuracy to Ti.Geolocation.ACCURACY_BEST_FOR_NAVIGATION, I did not see a negative value for speed. Again this was only within a couple hours of testing, so the negative could be so intermittent that it did not show in that time.
Edited the code in the description to include the changes needed for it to run.
Looks like native behavior: - http://stackoverflow.com/a/4956243/5537752 - http://stackoverflow.com/questions/30098202/cllocationmanager-always-returning-speed-1 Still can check it though, but I am also pretty sure this cannot be an iOS issue, since all we do to return the speed is [this line](https://github.com/appcelerator/titanium_mobile/blob/master/iphone/Classes/GeolocationModule.m#L971) to bridge the native type to the JavaScript type.
It's very possible it's native behavior. If that is the case, the documentation for appcelerator needs to be updated to reflect if we are needing speed, then the navigation setting needs to be used.
[~amandavines] You are very correct! Here are my test-results (wrapping the test-case into a single file):
I was driving around the Apple campus (virtually, using the iOS Simulator) and I've got correct values. Anyway, when you do not have a clear GPS signal, it will have value anomalies around the speed like stated in the above links. Do you have a proper wording for a note we could add? I feel like I am not into it enough so far to word it properly. Maybe this? {quote} Due to the Apple Geolocation API, set the
Ti.Geolocation.accuracy
toTi.Geolocation.ACCURACY_BEST_FOR_NAVIGATION
in order to properly measure speed changes and prevent the application from returning-1
values inside thelocation
event. {quote} I would add this paragraph to thelocation
event docs (see exact wording in the PR below). Finally, I am still wondering why it would be different between 5.5.x and 6.x, there has been no change between those versions. If you can, please check that one again.PR: https://github.com/appcelerator/titanium_mobile/pull/9010 No backport required since docs are always pushed from master.
Text/wording changes are good and describe the issue/solution.