开发者

Zoom into group of points in the MapActivity (ItemizedOverlay) in Android

开发者 https://www.devze.com 2023-01-26 10:52 出处:网络
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

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开发者_StackOverflow中文版 MapActivity? If not, could you provide me sample code?


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);

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号