根据OSMDroid的一组位置确定合适的缩放级别

时间:2013-01-31 15:38:39

标签: android osmdroid

从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找到一种方法。是否有解决方案/类来帮助根据一组位置确定缩放级别?

3 个答案:

答案 0 :(得分:0)

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

 Mapview.zoomToBoundingBox(...)

设置缩放级别。

答案 1 :(得分: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);

答案 2 :(得分:0)

这对我有用:

double

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

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

geoPointes只是GeoPoint对象的列表。