的Andr​​oid如何计算最优的缩放级别? [英] Android how to calculate optimal zoom level?

查看:178
本文介绍了的Andr​​oid如何计算最优的缩放级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何计算的跟踪路线缩放级别完全适合于地图(屏幕)的看法?
我有根/整条赛道的起点和终点/在经度/纬度的位置,我能计算出与输入参数表的缩放级别,但有多少米,我需要设置?我想在地图上显示的记录轨道。我发现赛道,但不适合的地图。

How can I calculate the zoom level for the tracked route to fit perfectly to the view of map(screen)? I have the start and end point of root/whole track/ in Lon/Lat position, I able to calculate the zoom level with input parameter meter, but how many meters need I set? I would like to show the logged track on the map. I showed the track but doesn't fit into map.

推荐答案

您可以通过这个code段变焦,只需要传递的起点和终点的GeoPoint在列表中。如果你有2点多它也可以。

You can set the zoom with this code snippet, just need to pass the starting and ending geopoint in a list. If you have more than 2 points it also works.

private void fixZoom(MapController controller, List <GeoPoint> items){

    int minLat = Integer.MAX_VALUE;
    int maxLat = Integer.MIN_VALUE;
    int minLon = Integer.MAX_VALUE;
    int maxLon = Integer.MIN_VALUE;

    for (GeoPoint item : items) 
    { 

          int lat = item.getLatitudeE6();
          int lon = item.getLongitudeE6();

          maxLat = Math.max(lat, maxLat);
          minLat = Math.min(lat, minLat);
          maxLon = Math.max(lon, maxLon);
          minLon = Math.min(lon, minLon);
     }

    controller.zoomToSpan((int) (Math.abs(maxLat - minLat) * 1.1), (int)(Math.abs(maxLon - minLon) * 1.1)); //1.1 to have some padding on the edges.
    controller.animateTo(new GeoPoint( (maxLat + minLat)/2,(maxLon + minLon)/2 )); //so the center is positioned just in the middle

}

希望有所帮助。

这篇关于的Andr​​oid如何计算最优的缩放级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆