1

I have an app that needs to get location to work and everything goes smoothly except when (from what i've gathered researching about this) my app is the first one to request a location and no lat and long have yet been retrieved.

How can I get location in this situation?

Thank you.

DomeWTF
  • 2,342
  • 4
  • 33
  • 46

1 Answers1

0

You call getLocationUpdates and pass in the callback. From your post I assume you're calling getLastKnownLocation. Don't do that- that function should only be used as a minor optimization, you should always assume you need to call getLocationUpdates or getSingleUpdate.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I'm actually using this: LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); – DomeWTF May 30 '17 at 01:43
  • Then you should get a response eventually- as long as the phone has location enabled, you have the correct permissions set, and its capable of getting a location fix (wireless enabled for network and able to talk to the google servers, capable of contacting the satellites for GPS (usually this means you need to be outdoors)). It may take a few seconds, but should come relatively quickly, if it can get a fix. If it can't, it may never come and there's no way to speed it up- that means the phone just doesn't know. – Gabe Sechan May 30 '17 at 01:46
  • The only way i found is to open google maps before the app, that gets a fix on a location and opening my app afterwards, that too gets a location, seems strange – DomeWTF May 30 '17 at 14:18