[英]Android: Algorithm to set zoom and location of Google map given a sets a points
I have an ArrayList, each of these LatLng is a marker on my map The list can have anywhere from 0 to 1 to n points. 我有一个ArrayList,每个LatLng都是我的地图上的标记。该列表可以包含0到1到n个点。 They may or may not be distant within each others.
它们彼此之间可能遥远,也可能不遥远。
Can someone help me, given a height ("h"dp) and a width ("w"dp) of the map area, determine: 给定地图区域的高度(“ h” dp)和宽度(“ w” dp),有人可以帮助我确定:
To find the center of a set of LatLng points: 要找到一组LatLng点的中心,请执行以下操作:
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (LatLng point: pointSet) {
builder.include( point);
}
LatLngBounds bounds = builder.build();
LatLng centerPoint = bounds.getCenter();
As for zooming, the simplest way would be to call map.animate: 至于缩放,最简单的方法是调用map.animate:
mapObj.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, PADDING_VALUE));
Which is guaranteed to set the map to the greatest zoom level that contains the bounds input (plus padding). 确保将地图设置为包含边界输入(加上填充)的最大缩放级别。
And if you're still interested in knowing the required zoom level: 如果您仍然对知道所需的缩放级别感兴趣:
float zoomLevel = mapObj.getCameraPosition().zoom; // call after(!) animateTo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.