Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23135] Android: "locationServicesEnabled" returns false when available on device

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-02-23T16:35:06.000+0000
Affected Version/sRelease 5.2.1
Fix Version/sRelease 7.1.0
ComponentsAndroid
Labelsandroid
ReporterFokke Zandbergen
AssigneeJoshua Quick
Created2016-04-01T18:29:57.000+0000
Updated2018-03-06T22:34:06.000+0000

Description

On an Android 6.0 device Ti.Geolocation.locationServicesEnabled will return false while it works fine. On an Android 4.4.4 emulator it returns true while it does not. Meanwhile [documentation](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Geolocation-property-locationServicesEnabled) says since Android 2.2 it will always return true because of the "passive" location provider but looking at the [source](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Geolocation-property-locationServicesEnabled) it filters that out.
var win = Ti.UI.createWindow();

var btn = Ti.UI.createButton({
  title: 'Click Me'
});

btn.addEventListener('click', function(e) {
  console.log('Ti.Geolocation.locationServicesEnabled ' + Ti.Geolocation.locationServicesEnabled);

  console.log('Ti.Geolocation.hasLocationPermissions() ' + Ti.Geolocation.hasLocationPermissions());

  if (Ti.Geolocation.hasLocationPermissions()) {
    getCurrentPosition();

  } else {
    Ti.Geolocation.requestLocationPermissions(null, getCurrentPosition);
  }
});

function getCurrentPosition() {
  Ti.Geolocation.getCurrentPosition(function(e) {
    console.log('Ti.Geolocation.getCurrentPosition() ' + JSON.stringify(e));
  });
}

win.add(btn);
win.open();
*Android 6.1*
[INFO]  Ti.Geolocation.locationServicesEnabled false
[INFO]  Ti.Geolocation.hasLocationPermissions() false
[INFO]  Ti.Geolocation.getCurrentPosition() {"code":0,"provider":{"power":1,"name":"network","accuracy":2},"coords":{"altitude":0,"speed":0,"longitude":5.9043011,"heading":0,"latitude":52.9589968,"timestamp":1459535042207,"altitudeAccuracy":null,"accuracy":22.777000427246094},"success":true}
*Android 4.4.4*
[INFO]  Ti.Geolocation.locationServicesEnabled true
[INFO]  Ti.Geolocation.hasLocationPermissions() true
[ERROR] GeolocationModule: (KrollRuntimeThread) [3070,3070] Unable to get current position, location is null
[INFO]  Ti.Geolocation.getCurrentPosition() {"error":"location is currently unavailable.","success":false,"code":6}

Comments

  1. Maggie Chen 2017-03-22

    PR https://github.com/appcelerator/titanium_mobile/pull/8903/
  2. Lokesh Choudhary 2017-04-14

    FR passed.
  3. Lokesh Choudhary 2017-05-08

    Verified the fix. Ti.Geolocation.locationServicesEnabled returns true as expected. Closing. Studio Ver: 4.9.0.201704240654 SDK Ver: 6.1.0.v20170508081747 OS Ver: 10.12.3 Xcode Ver: Xcode 8.3.2 Appc NPM: 4.2.9 Appc CLI: 6.2.0 Ti CLI Ver: 5.0.12 Alloy Ver: 1.9.11 Node Ver: 6.10.1 Java Ver: 1.8.0_101 Devices: > google Nexus 6 --- Android 6.0.1 > google Nexus 6P --- Android 7.1.1 > Samsung galaxy S3 --- Android 4.4.2
  4. Adriano Massi 2017-07-30

    I still have this issue with 6.1.1.
  5. Eric Merriman 2017-08-02

    [~adriano72] Can you provide a little more detail about your particular case? We can look into it.
  6. Suraj Datta 2017-11-23

    Hello All, I'm still getting *false* with the use of Ti.Geolocation.locationServicesEnabled. Tested this on Android device with os version 6 & 7. Turning Location services on or off returns same value. Steps i was performing to get location: 1) checking for location permission using hasLocationPermissions() --- This works perfect 2) Check whether location service is On/Off using Ti.Geolocation.locationServicesEnabled -- Returns false always. I'm using Titanium SDK: 6.3.0 Any help would be appreciated. Thanks.
  7. Joshua A. Ceaser 2017-11-27

    I'm having the same issue.
  8. Joshua A. Ceaser 2017-11-27

    I'm having the same issue, testing on Nexus 6 Android 7.1.1 and I'm able to reproduce this with SDK 6.3.0
  9. Suraj Datta 2017-11-30

    Hi, Do we've any PR for this issue?
  10. Maggie Chen 2017-11-30

    Hi all, I'm currently working on it. Sorry for the inconvenience, will update soon.
  11. Maggie Chen 2017-11-30

    PR https://github.com/appcelerator/titanium_mobile/pull/9633
  12. Maggie Chen 2017-12-13

    7_0_X PR https://github.com/appcelerator/titanium_mobile/pull/9682 {color:red}[This PR has been closed.]{color}
  13. Joshua A. Ceaser 2018-01-17

    Can this be put in to the 7.0.2 release?
  14. Joshua Quick 2018-02-16

    PR (7.1.x): https://github.com/appcelerator/titanium_mobile/pull/9840
  15. Lokesh Choudhary 2018-02-23

    FR's passed. PR's merged.
  16. Lokesh Choudhary 2018-03-06

    Verified the fix in SDK 7.2.0.v20180305152636 & 7.1.0.v20180306061214. Closing. Studio Ver: 5.0.0.201712081732 OS Ver: 10.13.2 Xcode Ver: Xcode 9.2 Appc NPM: 4.2.12 Appc CLI: 7.0.2 Daemon Ver: 1.0.1 Ti CLI Ver: 5.0.14 Alloy Ver: 1.11.0 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 5 — Android 6.0.1 ⇨ google Nexus 6P — Android 8.0.0

JSON Source