react-native-fused-location icon indicating copy to clipboard operation
react-native-fused-location copied to clipboard

Not returning location when location method is "Device only"

Open hortemo opened this issue 7 years ago • 11 comments

Hi! I am not able to get a location when using:

  • getFusedLocation(true)
  • FusedLocation.Constants.BALANCED
  • ACCESS_FINE_LOCATION
  • Location method "Device only"

This is on a real device for which i.e. Google Maps works fine. It works fine for other location methods (High Accuracy and Battery Saving).

Is this your experience as well, or is it most likely something on my part?

hortemo avatar Dec 17 '17 23:12 hortemo

Hi! Does it go inside the catch statement or the promise just never resolves?

MustansirZia avatar Dec 18 '17 09:12 MustansirZia

Also, what do you mean by Location method "Device only"?

MustansirZia avatar Dec 18 '17 16:12 MustansirZia

Well Android has 3 Location modes that you can set: High accuracy, Battery saving and device only. He must be referring to the later.

lone-cloud avatar Dec 19 '17 00:12 lone-cloud

Yes, I am talking about the location mode in Android settings. I get no error, it just never returns any location data.

hortemo avatar Dec 19 '17 15:12 hortemo

Hi @hortemo! A more likely cause for this problem is that since you're using Device only and forcing a new location update your device is not able to get a location as your device maybe somewhere indoors or has a poor internet connection. You've optimally set the mode to BALANCED but externally forced your device to get a new location from your GPS only. I think I should probably implement a timeout feature just so these cases are taken care of.

MustansirZia avatar Jan 03 '18 15:01 MustansirZia

@MustansirZia - Hi, I am also facing the same issue. I have tried to change Location Priority as HIGH_ACCURACY but still getting the same issue.

In some of the devices its getting lastLocation as null and getting request.getPriority() = 100 but is is not able to get location again and it is not going in catch block also.

Neha1490 avatar Jan 15 '18 10:01 Neha1490

@MustansirZia the problem seems to be that if the device setting is set to "Device Only" (GPS only), trying to get the location with "balanced" accuracy never works (irregardless of GPS signal strength). This can be replicated easily in the simulator. A timeout is a good idea. Reading this setting and acting accordingly would be even better.

EDIT: According to https://stackoverflow.com/questions/35830987/fused-location-provider-is-there-a-way-to-check-if-a-location-update-failed, it would be good to replace the LocationListener here with a LocationCallback, which has a onLocationAvailability method which is always executed and provides a status regarding the availability of the location (meanwhile the onLocationChanged method of the LocationListener has no guarantees on being executed).

sraka1 avatar Feb 18 '18 00:02 sraka1

@sraka1 You're probably right, it's about time we make use of a more appropriate callback. LocationCallback does seem a better way to go than the original LocationListener . This requires attention. I still, however, want to know why the "balanced" accuracy fails with "Device Only", that also requires some attention. Whenever I get time I'm going to look at this and hopefully come up with an update.

MustansirZia avatar Feb 19 '18 19:02 MustansirZia

Package updated to 0.2.1 8f64dbb5922d320bc048d824ba799eb8411c467c which makes use of LocationCallback instead of LocationListener. This would guarantee that the promise would get rejected if no suitable location could be returned (Fresh or old). As @sraka1 had pointed out earlier, LocationListener had no way of knowing that the request had failed inside it so a LocationCallback was a good way to go. This should also eliminate the need for a timeout.

MustansirZia avatar Feb 28 '18 16:02 MustansirZia

actually just saw this bug. If no one else is working on it, ill try to find some time in the next few days and look at it.

ingvardm avatar Mar 06 '18 15:03 ingvardm

It didn't go inside catch statement? Which version of the library are you using?

MustansirZia avatar Mar 06 '18 15:03 MustansirZia