gpt4 book ai didi

Android:在谷歌地图中设置缩放级别以包括所有标记点

转载 作者:IT王子 更新时间:2023-10-28 23:56:07 28 4
gpt4 key购买 nike

我正在尝试在 android 中设置 map 的缩放级别,使其包含我列表中的所有点。我正在使用以下代码。

int minLatitude = Integer.MAX_VALUE;
int maxLatitude = Integer.MIN_VALUE;
int minLongitude = Integer.MAX_VALUE;
int maxLongitude = Integer.MIN_VALUE;

// Find the boundaries of the item set
// item contains a list of GeoPoints
for (GeoPoint item : items) {
int lat = item.getLatitudeE6();
int lon = item.getLongitudeE6();

maxLatitude = Math.max(lat, maxLatitude);
minLatitude = Math.min(lat, minLatitude);
maxLongitude = Math.max(lon, maxLongitude);
minLongitude = Math.min(lon, minLongitude);
}
objMapController.zoomToSpan(
Math.abs(maxLatitude - minLatitude),
Math.abs(maxLongitude - minLongitude));

这有时有效。但是,有时某些点未显示,我需要然后缩小以查看这些点。有没有办法解决这个问题?

最佳答案

Android Map API v2 的另一种方法:

private void fixZoom() {
List<LatLng> points = route.getPoints(); // route is instance of PolylineOptions

LatLngBounds.Builder bc = new LatLngBounds.Builder();

for (LatLng item : points) {
bc.include(item);
}

map.moveCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50));
}

关于Android:在谷歌地图中设置缩放级别以包括所有标记点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5114710/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com