0

If I want all my POIs to be visible in the Map, then I need to adjust two parameters dynamically:

  • Center-Focus of the Map
  • Zoom step

I am wondering if there is such a behavior already built into the MapActivity? If not, could you provide me sample code?

OneWorld
  • 17,512
  • 21
  • 86
  • 136

1 Answers1

0

The answer is not to find the centre point amongst a group of points and then call mapController.zoomToSpan(centrePoint). Instead, do the following in your ItemizedOverlay:

public void calculateMapBounds()
{       
    int minLat = Integer.MAX_VALUE;
    int minLon = Integer.MAX_VALUE;
    int maxLat = Integer.MIN_VALUE;
    int maxLon = Integer.MIN_VALUE;

    for (LocatorPosition position : mPositions)
    {
        minLat = Math.min(position.getLatitudeE6(), minLat);
        minLon = Math.min(position.getLongitudeE6(), minLon); 
        maxLat = Math.max(position.getLatitudeE6(), maxLat); 
        maxLon = Math.max(position.getLongitudeE6(), maxLon);
    }

    spanLat = maxLat - minLat;
    spanLon = maxLon - minLon;

}

Then call mapController.zoomToSpan(spanLat, spanLon);

John J Smith
  • 11,435
  • 9
  • 53
  • 72