I am trying to acquire my location for an application I am working on. However I receive an error then force close when it tries to select the best provider. Any help on the issue would be much appreciated...do I need to declare something in onCreate in order for it to work? Here is a snippet of code followed by the error:
public void onStart(){
super.onStart();
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
best = locationManager.getBestProvider(criteria, true);//Selects best location provider given options between GPS and poor man's
locationProvider = locationManager.getProvider(best);
if (locationProvider != null) {
locationManager.requestLocationUpdates(locationProvider.getName(), 60000, 1,
this.locationListenerRecenterMap);
} else {
Log.e(TAG, "NO LOCATION PROVIDER AVAILABLE");
Toast.makeText(this, "The GPS location provider is not available at this time.", Toast.LENGTH_SHORT).show();
finish();
}
GeoPoint location = this.getLastKnownPoint();
this.mapController.animateTo(location);
}
public void onResume(){
super.onResume();
locationManager.requestLocationUpdates(best, 15000, 1, (LocationListener) this);
}
public void onPause(){
locationManager.removeUpdates((LocationListener) this);
}
private GeoPoint getLastKnownPoint(){
GeoPoint lastKnownPoint = GeoUpdateHelper.SCRANTON;
Location lastKnownLocation = this.locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(lastKnownLocation != null){
lastKnownPoint = GeoUpdateHelper.getGeoPoint(lastKnownLocation);
}else{
lastKnownPoint = GeoUpdateHelper.SCRANTON;
}
return lastKnownPoint;
}
And here is the error:
04-16 19:07:25.077: ERROR/AndroidRuntime(4998): Caused by: java.lang.IllegalArgumentException: name==null
04-16 19:07:25.077: ERROR/AndroidRuntime(4998): at android.location.LocationManager.getProvider(LocationManager.java:324)
04-16 19:07:25.077: ERROR/AndroidRuntime(4998): at com.example.mapMain.onStart(mapMain.java:76)
EDIT: This is running on my OG Droid. When I click to open the map part of the application which gets the location it force closes.