getLastKnownLocation getting null ?

Put your problem here if it does not fit any of the other categories.

getLastKnownLocation getting null ?

Postby JamesAndroid » Wed Dec 16, 2009 7:10 pm

Hi guys.

I am facing with problem related Location API.

I tried the following code :

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location loc = getLastKnownLocation(LocationManager.GPS_PROVIDER);

loc is always null, when call getLastKnownLocation.

?

what is wrong ?

Please advice guys.
JamesAndroid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Dec 07, 2009 7:23 am

Top

Postby stifry » Thu Dec 17, 2009 12:06 am

This means that there is no last location. This is in the case that the GPS has been off for awhile. A better solution is to register for GPS updates and wait for an updated location.

Jeff
Visit Trackaroo.com!
Trackmaster - Motorsports Lap Timer
Dynomaster - Performance Dyno
Image Image
User avatar
stifry
Developer
Developer
 
Posts: 46
Joined: Tue Feb 17, 2009 7:50 pm

Postby JamesAndroid » Thu Dec 17, 2009 12:43 am

thanks.

I need to get location on 2 activities.

So, Do I need declare on both following listener ?

private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}

Thanks in advance.
JamesAndroid
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Dec 07, 2009 7:23 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 17 guests