Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20356] Android Marshmallow is not showing geolocation request alert

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2016-02-12T03:14:39.000+0000
Affected Version/sRelease 5.1.2, Release 5.1.1
Fix Version/sn/a
Componentsn/a
LabelsAndroid, geolocation, notable
Reporter Ricardo Ramirez
AssigneeEric Merriman
Created2016-02-05T17:14:05.000+0000
Updated2017-06-02T19:24:33.000+0000

Description

Issue Description

Trying to get user location on a device with Marshmallow on Android, the Marshmallow OS should show the geolocation request as described as follows - http://developer.android.com/training/permissions/requesting.html

Steps to Replicate

Create a new classic mobile default project

Paste the next code:

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

var win = Titanium.UI.createWindow({  
    title:'Geolocation on Marshallow',
    backgroundColor:'#fff'
});

var label = Titanium.UI.createLabel({
	color: '#000',
	text: 'Tap Me',
	textAlign: 'center',
	left: 0,
	top: 0,
	width: Ti.UI.FILL,
	height: Ti.UI.FILL
});

Titanium.Geolocation.purpose = 'Get Current Location';

label.addEventListener('click', function (event) {
	Ti.API.error('Calling Ti.Geolocation.getCurrentPosition');
	if (Ti.Geolocation.locationServicesEnabled) {
		Ti.Geolocation.getCurrentPosition(function (event) {
			Ti.API.error('Ti.Geolocation.getCurrentPosition Callback Success: ' + event.success);
			/*
	    	Ti.UI.createAlertDialog({                                                                                                                                                                                                                                
	      		title: 'Geolocation',
	      		message: 'Success: ' + event.success,
	      		ok: 'OK'
	    	}).show();
	    	*/
	    	
			if (event.error) {
	            Ti.API.error('Error: ' + event.error);
	        } else {
	            Ti.API.info(event.coords);
	        }
	    });    
	}else{
		alert("location services not enabled");
	}    
});

win.add(label);
win.open();

Run on Android Marshmallow device

Marshmallow geolocation request OS should work as described here: http://developer.android.com/training/permissions/requesting.html

Comments

  1. Lokesh Choudhary 2016-02-08

    If geolocation permissions are not granted on android 6.0.1 I get an alert location services not enabled which is the right behaviour. I am able to see geolocation results on Marshmellow (6.0.1) & SDK 5.1.2.GA My logs:
       [ERROR] :  Calling Ti.Geolocation.getCurrentPosition
       [ERROR] :  Ti.Geolocation.getCurrentPosition Callback Success: true
       [INFO] :   {"altitude":0,"speed":0,"longitude":-121.9131316,"heading":0,"latitude":37.3678666,"timestamp":1454975067563,"altitudeAccuracy":null,"accuracy":50}
       
    NOTE: You might want to do JSON.Stringify the event.coords
       Ti.API.info(JSON.stringify(event.coords));
       
    or else it will show [Object Object] Environment: Appc Studio : 4.5.0.201602070910 Ti SDK : 5.1.2.GA Ti CLI : 5.0.6 Alloy : 1.7.33 MAC Yosemite : 10.10.5 Appc NPM : 4.2.3-2 Appc CLI : 5.2.0-249 Node: 4.2.2 Nexus 6P - Android 6.0.1
  2. Ricardo Ramirez 2016-02-08

    Cool !, the request alert is showing ?
  3. Lokesh Choudhary 2016-02-09

    [~rramirez], What do you mean by request alert ? When I tap Tap Me label & if location permissions are not unable I get alert location services not enabled. The code in the description does not ask for permissions just checks for them.
  4. Ricardo Ramirez 2016-02-09

    This is the expected behavior with the request alert: http://developer.android.com/training/permissions/requesting.html
  5. Lokesh Choudhary 2016-02-09

    [~rramirez], the white colored alert asking requesting for permission will only be seen if you request it. If you want to see it then do this :
       label.addEventListener('click', function (event) {
       	Ti.API.error('Calling Ti.Geolocation.getCurrentPosition');
       	if (Ti.Geolocation.locationServicesEnabled) {
       		Ti.Geolocation.getCurrentPosition(function (event) {
       			Ti.API.error('Ti.Geolocation.getCurrentPosition Callback Success: ' + event.success);
       			/*
       	    	Ti.UI.createAlertDialog({                                                                                                                                                                                                                                
       	      		title: 'Geolocation',
       	      		message: 'Success: ' + event.success,
       	      		ok: 'OK'
       	    	}).show();
       	    	*/
       	    	
       			if (event.error) {
       	            Ti.API.error('Error: ' + event.error);
       	        } else {
       	            Ti.API.info(JSON.stringify(event.coords));
       	        }
       	    });    
       	}else{
       		Ti.Geolocation.requestLocationPermissions();
       	}    
       });
       
  6. Ricardo Ramirez 2016-02-11

    Ok, now I understand, the Android request alert is not automatically prompted if you try to get the position and you don't have the permissions so you need to use the requestLocationPermissions method to show the alert, authorize the permissions and try again to get the position. Thanks !
  7. Chee Kiat Ng 2016-02-12

    [~bimmel] This may need to be clearer in docs.
  8. (deactived) Brian Immel 2016-02-12

    Added the following statement to http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Geolocation-method-requestLocationPermissions "If the user asks for permissions or tries to get unauthorized location information, then the app should call the request method to show the permission settings." I will publish this updated yml file next week when I push the next set of release notes.
  9. Lee Morris 2017-06-02

    Closing ticket with reference to the above comments.

JSON Source