-1
 String serviceString = Context.LocationService;
 lm = (LocationManager)GetSystemService(serviceString);
bestProvider = lm.GetBestProvider(cr, true);
 Location l = lm.GetLastKnownLocation(bestProvider);

l shows null value where the best provider is network

sonal
  • 39
  • 6

1 Answers1

0

You can configure the location via telnet if you use an emulator.. maybe thats why it shows null values...

see also this post click me

Community
  • 1
  • 1
fnkbz
  • 1,189
  • 1
  • 12
  • 22
  • I dont have problem with emulator,but i've problem working it on my device – sonal Jan 22 '14 at 19:11
  • have you add the permissions in the manifest file? ` ` – fnkbz Jan 22 '14 at 19:28
  • Also i found similar questions with yours..check them out http://stackoverflow.com/questions/11702848/getlastknownlocations-always-returns-null?rq=1 http://stackoverflow.com/questions/10681369/getlastknownlocation-returns-null-value-on-nexus?rq=1 the last known location is only available if the location has been determined by another app prior to your call. start maps or some other app and let it get a location lock. then run your app. – fnkbz Jan 22 '14 at 19:31
  • Hey! i got the answer! i dont think we require to add mock_location. we just need to start gps or map application for the first time and later my application works – sonal Jan 22 '14 at 19:43