gpt4 book ai didi

android - 在 android 中的谷歌地图上设置缩放级别

转载 作者:行者123 更新时间:2023-11-29 21:56:50 25 4
gpt4 key购买 nike

我需要在谷歌地图上以最大缩放级别显示我的当前位置和目标位置。这是我的代码,用于显示最大缩放的两个位置。但它会缩放到两个位置的中心,而我的位置正在消失。我希望我的两个位置都应在 View 范围内,并尽可能将缩放设置为最大。请帮我。提前致谢。

    mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapMarker = getResources().getDrawable(R.drawable.map_marker);

overlayList = mapView.getOverlays();
myMap = new MyLocationOverlay(this, mapView);
myMap.enableMyLocation();

mapController = mapView.getController();

GeoPoint geoPoint = new GeoPoint((int) (targetLatitude * 1E6), (int) (targetLongitude * 1E6));

mapController.animateTo(new GeoPoint(((int) (targetLatitude * 1E6) + (int) (currentLatitude * 1E6))/2, ((int) (targetLongitude * 1E6) + (int) (curLongitude * 1E6))/2 ));
mapController.zoomToSpan((int)(targetLatitude - currentLatitude), (int)(targetLongitude - curLongitude));

mapController.setZoom(12);

OverlayItem overlayItem = new OverlayItem(geoPoint,"xxx", "yyyy");

CustomPinpoint customPinpoint = new CustomPinpoint(mapMarker, this);
customPinpoint.insertPinpoint(overlayItem);

overlayList.clear();
overlayList.add(myMap);
overlayList.add(customPinpoint);

最佳答案

    int minLat = Integer.MAX_VALUE;
int minLong = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int maxLong = Integer.MIN_VALUE;

for (GeoPoint point : points) {
minLat = Math.min(point.getLatitudeE6(), minLat);
minLong = Math.min(point.getLongitudeE6(), minLong);
maxLat = Math.max(point.getLatitudeE6(), maxLat);
maxLong = Math.max(point.getLongitudeE6(), maxLong);
}

MapController controller = view.getController();
controller.zoomToSpan(
Math.abs(minLat - maxLat), Math.abs(minLong - maxLong));
controller.animateTo(new GeoPoint((maxLat + minLat) / 2,
(maxLong + minLong) / 2));

关于android - 在 android 中的谷歌地图上设置缩放级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13024957/

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