I believe all you need to do is call mapView.invalidate()
, I set up my maps a little differently then yours, I have copied my code below for reference:
LocationManager jLocManager;
MapController mController;
GeoPoint geoP;
MapView mapView;
MyLocationOverlay myLocOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
try {
JJMapsInitialize();
}catch(Exception e){
Log.e("JJMapsInitialize", "FAILED: " + e.getMessage());
}
myLocOverlay = new MyLocationOverlay(this, mapView);
myLocOverlay.enableMyLocation();
mapView.getOverlays().add(myLocOverlay);
}
public void findMyLocation() {
LocationManager jLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// 35000 is 35 seconds to find location && 10 is the minimum distance in meters
jLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 10, this.jLocListener);
jLocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 3000, 10, this.jLocListener);
}
private void JJMapsInitialize() {
try {
mapView = (MapView) findViewById(R.id.mapview);
mapView.displayZoomControls(true);
mapView.setBuiltInZoomControls(true);
mController.animateTo(geoP);
mController.setZoom(10);
mapView.invalidate();
} catch(Exception e) {
Log.e("JJMapsInitialize", "FAILED: " + e.getMessage());
}
try {
findMyLocation();
} catch (Exception e) {
Log.e("findMyLocation", "FAILED: " + e.getMessage());
}
}
As you can see I call the initialize method in which I set up my MapView
with controls, invalidate and then add my overlays.
EDIT
jLocListener
is just my LocationListener()
- My first name starts with a "j" so I generally use my initial or both initials in my naming conventions.
public LocationListener jLocListener = new LocationListener() {
//class findMe implements LocationListener {
public void onLocationChanged(Location location) {
try {
lat = location.getLatitude();
lon = location.getLongitude();
} catch (Exception e) {
Log.e("onLocationChanged", "FAILED: " + e.getMessage());
}
}
public void onProviderDisabled(String provider) {
Log.i("LocationListener", "onProviderDisabled");
}
public void onProviderEnabled(String provider) {
Log.i("LocationListener", "onProviderEnabled");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.i("LocationListener", "onStatusChanged");
}
};