Not Able To Get Location By Gps : Android
I am new to android. I am trying to get my location using GPS. I have included the permissions: <
Solution 1:
locationManager.getLastKnownLocation will return null if the GPS has not had time to get a fix yet. Android does not provide a 'give me the location now' method. When the GPS has got a fix, the onLocationChanged() will run. It is event driven, you have to be patient and wait for that event. Once onLocationChanged() has run, then getLastKnownLocation() will return a non null value.
Solution 2:
Are you running it on emulator or device? If on emulator, you may need to send GPS data manually to emulator via "emulator control". In eclipse, you can find it Window>Open Perspective>DDMS.
If you are running on device, is it possible your device never received a GPS signal before?
Solution 3:
Try to replace the last line by:
List<String> providers = locationManager.getProviders(true);
if(!providers.isEmpty()) {
location = locationManager.getLastKnownLocation(providers.get(0));
} else {
Log.d("ManualLog", "No provider");
}
Post a Comment for "Not Able To Get Location By Gps : Android"