[AC-1778] iOS: getCurrentPosition returns {}
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2013-12-11T05:58:38.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | n/a |
Reporter | Martin Guillon |
Assignee | Ritu Agrawal |
Created | 2012-10-12T14:00:08.000+0000 |
Updated | 2016-03-08T07:40:40.000+0000 |
Description
It works every time on the simulator.
I get {} on my device.
var win = Ti.UI.createWindow({
backgroundColor : 'white'
});
var currentLocationLabel = Titanium.UI.createLabel({
text : 'Current Location (One Shot)',
font : {
fontSize : 12,
fontWeight : 'bold'
},
color : '#111',
top : 110,
left : 10,
height : 15,
width : 300
});
win.add(currentLocationLabel);
var currentLocation = Titanium.UI.createLabel({
text : 'Current Location not fired',
font : {
fontSize : 11
},
color : '#444',
top : 130,
left : 10,
height : 15,
width : 300
});
win.add(currentLocation);
Ti.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Ti.Geolocation.distanceFilter = 10;
Ti.Geolocation.purpose = "Geo-Location";
function translateErrorCode(code) {
if (code == null) {
return null;
}
switch (code) {
case Ti.Geolocation.ERROR_LOCATION_UNKNOWN:
return "Location unknown";
case Ti.Geolocation.ERROR_DENIED:
return "Access denied";
case Ti.Geolocation.ERROR_NETWORK:
return "Network error";
case Ti.Geolocation.ERROR_HEADING_FAILURE:
return "Failure to detect heading";
case Ti.Geolocation.ERROR_REGION_MONITORING_DENIED:
return "Region monitoring access denied";
case Ti.Geolocation.ERROR_REGION_MONITORING_FAILURE:
return "Region monitoring access failure";
case Ti.Geolocation.ERROR_REGION_MONITORING_DELAYED:
return "Region monitoring setup delayed";
}
}
Titanium.Geolocation.getCurrentPosition(function(e) {
if (!e.success || e.error) {
currentLocation.text = 'error: ' + JSON.stringify(e.error);
Ti.API.info("Code translation: " + translateErrorCode(e.code));
alert('error ' + JSON.stringify(e.error));
return;
}
var longitude = e.coords.longitude;
var latitude = e.coords.latitude;
var altitude = e.coords.altitude;
var heading = e.coords.heading;
var accuracy = e.coords.accuracy;
var speed = e.coords.speed;
var timestamp = e.coords.timestamp;
var altitudeAccuracy = e.coords.altitudeAccuracy;
Ti.API.info('speed ' + speed);
currentLocation.text = 'long:' + longitude + ' lat: ' + latitude;
Titanium.API.info('geo - current location: ' + new Date(timestamp) + ' long ' + longitude + ' lat ' + latitude + ' accuracy ' + accuracy);
});
win.open();
After adding the translateErrorCode() function to the test case I found that iOS 4.3.5 (possibly iOS 5.1 as well) is returning Ti.Geolocation.ERROR_DENIED. It works fine on iOS 6. Tested with Ti SDK 3.0.2. Martin: Can you confirm whether you're getting the same error with the new test case, and also that it returns {} only on iOS 5.1 and not 6.0 (OS regression). Thanks!
[~farfromrefuge] We tried to reproduce this issue on iOS 5.1 iPad3, built with iOS SDK 6.0, and TiSDK 3.1.0. But we were not able to reproduce it. We can see the current positions on both simulator and device. Please let us know if the issue persists for you.
I have no idea where it stands right now. So you can close it if you want …
Closing it as per Martin's reply.