Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1778] iOS: getCurrentPosition returns {}

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-12-11T05:58:38.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterMartin Guillon
AssigneeRitu Agrawal
Created2012-10-12T14:00:08.000+0000
Updated2016-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();

Comments

  1. Daniel Sefton 2013-03-20

    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!
  2. Ritu Agrawal 2013-12-11

    [~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.
  3. Martin Guillon 2013-12-11

    I have no idea where it stands right now. So you can close it if you want …
  4. Shak Hossain 2013-12-11

    Closing it as per Martin's reply.

JSON Source