我需要在谷歌地图上以最大缩放级别显示我的当前和目标位置。这是我的代码,以显示最大缩放的两个位置。但它缩放到两个位置的中心和我的位置都不见了。我希望我的两个位置都应该在视图范围内,并尽可能将缩放设置为最大值。请帮我。提前致谢。
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);
答案 0 :(得分:2)
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));
答案 1 :(得分:0)
缩小缩放级别并为要修复标记的地理位置设置动画。