How to set screen zoom by geopoints?

醉酒当歌 提交于 2019-12-11 06:09:39

问题


I drew a line between 2 geopoints. How do I set screen zoom by these 2 geopoints. What I want to do is to show start and finish points by default. Is there any algorithm for that?


回答1:


here what I did :

private void centerMap() {

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

            for (Point point : twoPoints) {

                    int lat = (int) (point.getLatitude() * 1E6);
                    int lon = (int) (point.getLongitude() * 1E6);

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

                    mc.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon));
            mc.animateTo(new GeoPoint((maxLat + minLat) / 2, (maxLon + minLon) / 2));
    }

(Where mc is your MapController)



来源:https://stackoverflow.com/questions/13233831/how-to-set-screen-zoom-by-geopoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!