[英]How to calculate the map span/zoom to include a set of GeoPoints in the viewport?
[英]How to set screen zoom by geopoints?
我在两个地理位置之间划了一条线。 如何通过这两个地理位置设置屏幕缩放。 我想做的是默认显示起点和终点。 有什么算法吗?
在这里,我做了什么:
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));
}
(其中mc是您的MapController)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.