Reputation: 7
I have google maps activity where i would like to get my location but im facing NullPointerException...
locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
Location location = locManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
System.out.println("loaded4");
myPoint = new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));
System.out.println("loaded5");
I am able to get "loaded4" but not "loaded5" So NullPointer cause is between them. I also tried to use GPS_PROVIDER but it didnt work out.
Yes i have all permissions in manifest. Map is able to load in if im not searhing for my loacation.
Is it possible its NullPointer because before that i load some other coordinates in same class ? Maybe its emulator fault ? I can give extended code if needed. Using source from http://www.chupamobile.com/tutorial/details/53
Upvotes: 1
Views: 334
Reputation: 11623
locManager.getLastKnownLocation
returns null if the current service is turned off (checkout the documentation http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation%28java.lang.String%29) .
If you are using an emulator, then you need to send the location information. If you are using Eclipse, open the DDMS perspective and send the location data from the "Location Controls" panel. ( How to emulate GPS location in the Android Emulator? ).
Upvotes: 2