Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7565] Android: refactor Geolocation module to support expanded Android functionality

GitHub Issuen/a
TypeStory
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-03-13T20:18:13.000+0000
Affected Version/sRelease 1.8.1
Fix Version/sSprint 2012-05, Release 2.0.0
ComponentsAndroid
Labelsmodule_geolocation, qe-port
ReporterOpie Cyrus
AssigneeOpie Cyrus
Created2012-02-06T22:45:46.000+0000
Updated2017-03-22T17:02:02.000+0000

Description

Refactor geolocation module on Android according to internal Geolocation additions spec: https://wiki.appcelerator.org/display/spe/Geolocation+platform+additions Test case (heavily modified KS geo test):
var win = Ti.UI.createWindow({
	backgroundColor: 'yellow'
});



var providerPassive = Ti.Geolocation.Android.createLocationProvider({
	name: Ti.Geolocation.PROVIDER_PASSIVE,
	minUpdateDistance: 0.0,
	minUpdateTime: 0
});

var providerNetwork = Ti.Geolocation.Android.createLocationProvider({
	name: Ti.Geolocation.PROVIDER_NETWORK,
	minUpdateDistance: 0.0,
	minUpdateTime: 5
});

var providerGps = Ti.Geolocation.Android.createLocationProvider({
	name: Ti.Geolocation.PROVIDER_GPS,
	minUpdateDistance: 0.0,
	minUpdateTime: 0
});

var gpsRule = Ti.Geolocation.Android.createLocationRule({
	provider: Ti.Geolocation.PROVIDER_GPS,
	minAge: 10000
});



var button1 = Ti.UI.createButton({
	title: 'legacy network',
	top: 20,
	left: 20
});
button1.addEventListener('click', function(e) {
	Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_NETWORK;
	Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
	Ti.Geolocation.Android.manualMode = false;
});
win.add(button1);

var button2 = Ti.UI.createButton({
	title: 'legacy gps',
	top: 70,
	left: 20
});
button2.addEventListener('click', function(e) {
	Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
	Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
	Ti.Geolocation.Android.manualMode = false;
});
win.add(button2);

var button3 = Ti.UI.createButton({
	title: 'simple low',
	top: 120,
	left: 20
});
button3.addEventListener('click', function(e) {
	Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_LOW;
	Ti.Geolocation.Android.manualMode = false;
});
win.add(button3);

var button4 = Ti.UI.createButton({
	title: 'simple high',
	top: 170,
	left: 20
});
button4.addEventListener('click', function(e) {
	Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_HIGH;
	Ti.Geolocation.Android.manualMode = false;
});
win.add(button4);

var button5 = Ti.UI.createButton({
	title: 'manual network',
	top: 20,
	right: 20
});
button5.addEventListener('click', function(e) {
	Ti.Geolocation.Android.removeLocationProvider(providerPassive);
	Ti.Geolocation.Android.removeLocationProvider(providerGps);
	Ti.Geolocation.Android.addLocationProvider(providerNetwork);
	Ti.Geolocation.Android.manualMode = true;
});
win.add(button5);

var button6 = Ti.UI.createButton({
	title: 'manual network+gps',
	top: 70,
	right: 20
});
button6.addEventListener('click', function(e) {
	Ti.Geolocation.Android.removeLocationProvider(providerPassive);
	Ti.Geolocation.Android.addLocationProvider(providerNetwork);
	Ti.Geolocation.Android.addLocationProvider(providerGps);
	Ti.Geolocation.Android.manualMode = true;
});
win.add(button6);

var button7 = Ti.UI.createButton({
	title: 'manual gps',
	top: 120,
	right: 20
});
button7.addEventListener('click', function(e) {
	Ti.Geolocation.Android.removeLocationProvider(providerPassive);
	Ti.Geolocation.Android.removeLocationProvider(providerNetwork);
	Ti.Geolocation.Android.addLocationProvider(providerGps);
	Ti.Geolocation.Android.manualMode = true;
});
win.add(button7);

var button8 = Ti.UI.createButton({
	title: 'gps rule on',
	top: 170,
	right: 20
});
button8.addEventListener('click', function(e) {
	Ti.Geolocation.Android.addLocationRule(gpsRule);
});
win.add(button8);

var button9 = Ti.UI.createButton({
	title: 'gps rule off',
	top: 170,
	right: 110
});
button9.addEventListener('click', function(e) {
	Ti.Geolocation.Android.removeLocationRule(gpsRule);
});
win.add(button9);








var currentLocationLabel = Titanium.UI.createLabel({
	text:'Current Location (One Shot)',
	font:{fontSize:12, fontWeight:'bold'},
	color:'#111',
	top:260,
	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:280,
	left:10,
	height:15,
	width:300
});
win.add(currentLocation);

var updatedLocationLabel = Titanium.UI.createLabel({
	text:'Updated Location',
	font:{fontSize:12, fontWeight:'bold'},
	color:'#111',
	top:300,
	left:10,
	height:15,
	width:300
});
win.add(updatedLocationLabel);

var updatedLocation = Titanium.UI.createLabel({
	text:'Updated Location not fired',
	font:{fontSize:11},
	color:'#444',
	top:320,
	left:10,
	height:15,
	width:300
});
win.add(updatedLocation);

var updatedLatitude = Titanium.UI.createLabel({
	text:'',
	font:{fontSize:11},
	color:'#444',
	top:340,
	left:10,
	height:15,
	width:300
});
win.add(updatedLatitude);

var updatedLocationAccuracy = Titanium.UI.createLabel({
	text:'',
	font:{fontSize:11},
	color:'#444',
	top:360,
	left:10,
	height:15,
	width:300
});
win.add(updatedLocationAccuracy);

var updatedLocationTime = Titanium.UI.createLabel({
	text:'',
	font:{fontSize:11},
	color:'#444',
	top:380,
	left:10,
	height:15,
	width:300
});
win.add(updatedLocationTime);




Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;

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";
	}
}

var locationCallback = function(e) {
	if (!e.success || e.error)
	{
		updatedLocation.text = 'error:' + JSON.stringify(e.error);
		updatedLatitude.text = '';
		updatedLocationAccuracy.text = '';
		updatedLocationTime.text = '';
		Ti.API.info("Code translation: "+translateErrorCode(e.code));

		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;

	updatedLocation.text = 'long:' + longitude;
	updatedLatitude.text = 'lat: '+ latitude;
	updatedLocationAccuracy.text = 'accuracy:' + accuracy;
	updatedLocationTime.text = 'timestamp:' +new Date(timestamp);

	updatedLatitude.color = 'red';
	updatedLocation.color = 'red';
	updatedLocationAccuracy.color = 'red';
	updatedLocationTime.color = 'red';
	setTimeout(function()
	{
		updatedLatitude.color = '#444';
		updatedLocation.color = '#444';
		updatedLocationAccuracy.color = '#444';
		updatedLocationTime.color = '#444';
	},100);

	Titanium.API.info('geo - location updated: ' + new Date(timestamp) + ' long ' + longitude + ' lat ' + latitude + ' accuracy ' + accuracy);
};
Titanium.Geolocation.addEventListener('location', locationCallback);

win.open();


Comments

  1. Opie Cyrus 2012-03-08

    The test case shown in the descriptions handles switching between the various behavior modes now present in the new Geolocation module and applies a rule in one case among testing out other module level properties. Testers should first be familiar with the spec to understand what is going on in general and then perhaps change the test app to try out different combinations if desired. There are too many possible options to reasonably contain them all in a limited test app. Any questions, please contact me.
  2. Opie Cyrus 2012-03-11

    updated test case
  3. Lee Morris 2017-03-22

    Closing ticket as fixed.

JSON Source