2

I tried to get current user location on button press and show the address on screen.

I am using google fused location as follow

locationClient = LocationServices.getFusedLocationProviderClient(this)
locationRequest = LocationRequest()
locationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY
locationClient.requestLocationUpdates(locationRequest, callback, null)

and after I get the latitude and longitude, i resolve the address using geocoder as follow

addresses = geocoder.getFromLocation(
                    location.latitude,
                    location.longitude,
                    1)

The problem is that sometimes the address I get is not accurate. And if I minimize/close my apps, open Google Maps, and go back to my application again, the location that I get is accurate.

How do I fix these? Thanks

dito cesartista
  • 209
  • 1
  • 10
  • have look [this](https://stackoverflow.com/a/42739534/5110595) – Hemant Parmar Mar 07 '18 at 04:34
  • the answer there suggest to check the accuracy and goes to setting to ask the user to turn on GPS. In my case, even when the device's built in GPS is turned on, the location is still not accurate sometimes. – dito cesartista Mar 07 '18 at 04:57
  • is your map and play store service is updated?? – Hemant Parmar Mar 07 '18 at 05:00
  • Are you gettign the same results on an emulator? I've found actual devices to be far less accurate at times, due to signal fluctuations etc. – Ewald Mar 07 '18 at 05:02
  • @HemantParmar Yes my map and play services is updated. In fact, like I said, after I open google map and open my apps again, the location is accurate. – dito cesartista Mar 07 '18 at 06:46
  • @Ewald So far, on emulator, its accurate. But i'm not moving to different places when using emulator. Yes i reckon that there may be signal fluctuations, but what I dont understand is that when I open google map, and comeback to my application, its accurate. How does the google maps does that? – dito cesartista Mar 07 '18 at 06:46
  • That's interesting - and you are making sure you get a location mode of LOCATION_MODE_HIGH_ACCURACY back? Otherwise it's still firing up services in the background and the location might be a previously cached one. – Ewald Mar 07 '18 at 07:13

0 Answers0