Sometimes when trying to get the Latitude span or Longitude span of a mapview with getLatitudeSpan() and getLongitudeSpan() I get 0 and 360*1E6 respectively. This doesn’t happen always but it is a problem, has anybody got this problem? Any workarounds? I tried using getProjection() too but I get the same problem. Here is the piece of code:
MapView mapView = (MapView) findViewById(R.id.mapview);
int lat = mapView.getLatitudeSpan(); // sometimes returns 0
int long = mapView.getLongitudeSpan(); // sometimes returns 360*1E6
I would detect the condition and schedule your work to try again after a few hundred milliseconds. AFAIK, those values will eventually become available, but they may be rather timing-dependent. In theory, they should be calculated after you have set the center and set the zoom, but I suspect that they really aren’t being calculated until after the
MapViewis rendered, and possibly not until some map data from the Internet is downloaded.So, isolate your code that depends on those spans into a method. Call that method from
onCreate()and theAsyncTask, probably as you’re doing today. But, add detection logic to find the invalid values, then callpostDelayed()on yourMapView(or some otherView) to invoke your method again after a few hundred milliseconds if the values are invalid. You may also need to add some sort of counter so you don’t do thispostDelayed()stuff indefinitely.This, of course, is a hack. But, with the Google Maps component not being open source, it is difficult to come up with something more solid.