Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8517] iOS: Add Ti.Geolocation.ACCURACY_HIGH / ACCURACY_LOW

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2014-12-10T22:22:31.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sRelease 2.1.0, Sprint 2012-07, Release 2.0.1
ComponentsiOS
Labelsparity, qe-testadded
ReporterStephen Tramer
AssigneeStephen Tramer
Created2012-04-04T14:43:57.000+0000
Updated2014-12-10T22:22:32.000+0000

Description

iOS needs to support the two new "common" geolocation accuracy settings, by aliasing them to existing properties: Ti.Geolocation.ACCURACY_HIGH Ti.Geolocation.ACCURACY_LOW

Comments

  1. Stephen Tramer 2012-04-04

    Updated test from TIMOB-7565 to support cross-platform testing:
       function isAndroid() {
       	return (Ti.Platform.name === "android");
       }
       
       var win = Ti.UI.createWindow({
           backgroundColor: 'yellow'
       });
        
       if (isAndroid()) {
       	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
       	});
       }
        
       if (isAndroid()) {
       	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;
       	if (isAndroid()) {
           	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;
       	if (isAndroid()) {
       	    Ti.Geolocation.Android.manualMode = false;
       	}
       });
       win.add(button4);
        
       if (isAndroid()) {
       	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();
       
  2. Max Stepanov 2012-04-05

    PRs https://github.com/appcelerator/titanium_mobile/pull/1931 and https://github.com/appcelerator/titanium_mobile/pull/1941 are merged
  3. Eric Merriman 2012-06-13

    Verified feature working as expected with SDK 2.1.0.v20120612170248

JSON Source