[英]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.