1

I'm using Google Play Services to get the current location of the user. Basically I use the codes at http://www.androidhive.info/2015/02/android-location-api-using-google-play-services/ to get the location. So herein lies my problem:

1) I can get the current user location on my Xperia Mini (Running ICS) without any problem. If I didn't enable the GPS, the location that I'd receive (expectedly) isn't that accurate, but I will still get it. And if I enable the GPS, I would (again, expectedly) receive a much more accurate location.

2) But when I tried running my app on my Zenfone C (Running KitKat), if I didn't enable location, I would never get any location. getLastLocation and onLocationChanged will always return null. Only after I enable location, I'd get the location. But after I disable location and tried to getLastLocation again, it will again, return null.

The situation that occurs on my Zenfone C puzzles me, because from my understanding, even if we didn't enable location/GPS, we would still be able to get the current location from the mobile network or wifi triangulation, because that's what happening with my Xperia Mini, and I thought that should be the standard for all Android devices? Or is the enable location on/off on some Android devices have some other meaning? Perhaps on some device, when location is turned off, there's no way we can get the location. Can anyone here shed some light on this?

Thanks

imin
  • 4,504
  • 13
  • 56
  • 103
  • There's multiple sub-modes for location mode when it's on. The UI varies in different Android versions. Take a look at the screenshots in this answer: http://stackoverflow.com/a/30580898 Did you have location mode completely off, or did you just disable GPS when you still got valid locations? – Daniel Nugent Aug 01 '15 at 16:10
  • Hmmm couldn't check it now since the phone is not with me currently. However I assume most users will just use the location toggle on/off which appears on the notification bar, without knowing in details what actually is being turned on/off. And assuming this is the case, it seems there's no fool-proof/sure way to get even an approximate location of the user on some phone models, if he/she disabled her location? – imin Aug 01 '15 at 16:25
  • There's no way for the device to get new locations once the location mode is set to off, but it's possible that the one device had a cached location from when the location mode was set to on. – Daniel Nugent Aug 01 '15 at 16:42
  • @DanielNugent I thought even if GPS is turned off, as long as the user still has it's internet (mobile data or wifi) turned on, by right we should be able to get his/her location right? – imin Aug 01 '15 at 16:54
  • Nope, network location needs to be enabled to get a location from mobile data or wifi. Note that if you use the toggle button, it enables/disables both network location and GPS. You can use the sub-modes to enable only one – Daniel Nugent Aug 01 '15 at 17:28
  • ok @DanielNugent thanks for your explanation.. that explains it I guess... I think you can give your last comment as the answer, so I can mark it. – imin Aug 02 '15 at 15:08

1 Answers1

1

There's no way for the device to get new locations once the location mode is set to off, but it's possible that the one device had a cached location from when the location mode was set to on.

Network location (Power saving mode on some Android versions) needs to be enabled to get a location from mobile data or WiFi. Note that if you use the toggle button, it enables/disables both network location and GPS (High Accuracy mode). You can use the sub-modes to enable only one location mode (Power Saving for Network only, or GPS only).

For more info, take a look at the screenshots in this answer.

Community
  • 1
  • 1
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • when both mobile data and wifi are turned on which is the priroity to get the location? – ThinkAndCode Apr 18 '21 at 08:01
  • @Mighty It will use all of the data that is available. It can get rough location data from cell tower triangulation, but it can get much better results from analyzing the WiFi hotspots in range. That is why you can actually get very precise location data from just WiFi, and also why you now need to prompt the location permission in order for your app to view any WiFi scan results. – Daniel Nugent Apr 19 '21 at 16:21
  • Thank you for your response. I would like to go deeper about how location services. Can you please tell(Redirect) me where I can get that info?. – ThinkAndCode Apr 20 '21 at 04:13