本文介绍了如何通过地址设置屏幕缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个地点之间画了一条线。如何通过这2个地点设置屏幕缩放。我想要做的是默认显示开始点和结束点。有什么算法吗?

解决方案

这里是我做的:

  private void centerMap(){

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

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

$ / code>

(其中mc是您的MapController)


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?

解决方案

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)

这篇关于如何通过地址设置屏幕缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:07