2

从 Google Maps Android API v2,我了解到这可以通过这种方法来完成:

LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Location loc : allLocations) {
    LatLng position = new LatLng(loc.getLatitude(), loc.getLongitude());
    builder.include(position);
}

CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(builder.build(), someMarginValue);
map.moveCamera(cu);

但是我似乎找不到为 OSMDroid 执行此操作的方法。是否有解决方案/类来帮助根据一组位置确定缩放级别?

4

3 回答 3

1

这对我有用:

    mapController.setZoom(10.0);
    map.post(new Runnable() {
        @Override
        public void run() {
            mapController.setCenter(boundingBox.getCenterWithDateLine());
            mapController.zoomToSpan(boundingBox.getLatitudeSpan(), boundingBox.getLongitudeSpan());
            map.invalidate();
        }
    });

没有初始缩放级别,它根本不起作用。第二部分 map.post 可以删除,但我认为它有助于 zoomToSpan() 在计算时处于 isLayoutOccurred() 状态。您可以像这样获得boundingBox:

final BoundingBox boundingBox = BoundingBox.fromGeoPoints(geoPoints);

geoPointes 只是 GeoPoint 对象的列表。

于 2018-12-15T00:21:25.780 回答
0

在 osmdroid 中,您可以从一组位置确定最小/最大坐标,然后调用

 Mapview.zoomToBoundingBox(...)

设置缩放级别。

于 2015-07-23T07:30:52.197 回答
0

这对我来说很好:

    ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
    waypoints.add(new GeoPoint(35.37, -119.01));
    waypoints.add(new GeoPoint(35.35, -119.01));
    waypoints.add(new GeoPoint(35.11, -118.32));
    waypoints.add(new GeoPoint(35.10, -118.32));
    waypoints.add(new GeoPoint(35.10, -118.15));
    waypoints.add(new GeoPoint(35.09, -118.14));
    waypoints.add(new GeoPoint(35.63, -117.88));
    waypoints.add(new GeoPoint(35.65, -117.72));
    waypoints.add(new GeoPoint(35.62, -117.67));

    final BoundingBoxE6 boundingBoxE6 = BoundingBoxE6.fromGeoPoints(waypoints);
    mMapView.zoomToBoundingBox(boundingBoxE6,true);
于 2016-03-10T06:13:01.263 回答