简体   繁体   中英

android google maps my location

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

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? ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM