I have gone through this exact same problem and the solutions stated above works. However I would like to present a more clear implementation for all the beginners out there.
Define a view variable for your map:
private MapView mapView;
And assign the mapview:
mapView = (MapView) findViewById(R.id.mapview);
Add the following method:
/**
* Wait for mapview to become ready.
*/
private Runnable waitForMapTimeTask = new Runnable() {
public void run() {
// If either is true we must wait.
if(mapView.getLatitudeSpan() == 0 || mapView.getLongitudeSpan() == 360000000)
mapView.postDelayed(this, TIME_TO_WAIT_IN_MS);
}
};
In your onCreate/onResume add the following prior to calling getLatitudeSpan:
mapView.postDelayed(waitForMapTimeTask, TIME_TO_WAIT_IN_MS);
And you are good to go :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…