1

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

    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); 
4

2 回答 2

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));
于 2012-10-23T07:08:32.017 回答
0

降低缩放级别并动画到您希望固定标记的地理点。

于 2012-10-23T07:34:02.483 回答