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
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:NOTE: You might want to do
JSON.Stringify
theevent.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.1Cool !, the request alert is showing ?
[~rramirez], What do you mean by request alert ? When I tap
Tap Me
label & if location permissions are not unable I get alertlocation services not enabled
. The code in the description does not ask for permissions just checks for them.This is the expected behavior with the request alert: http://developer.android.com/training/permissions/requesting.html
[~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 :
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 !
[~bimmel] This may need to be clearer in docs.
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.
Closing ticket with reference to the above comments.