Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将mapView缩放到osmdroid上的某个边界框_Android_Maps_Openstreetmap_Bounding Box - Fatal编程技术网

Android 将mapView缩放到osmdroid上的某个边界框

Android 将mapView缩放到osmdroid上的某个边界框,android,maps,openstreetmap,bounding-box,Android,Maps,Openstreetmap,Bounding Box,我想使用zoomToBoundingBox方法将地图缩放到特定的边界框。 该方法只在缩放级别0上显示地图 在mapView.java源代码中,我发现: /** *缩放贴图以尽可能靠近指定的边界框。 *必须在显示布局完成后调用,或者屏幕尺寸未知,并且 *将始终缩放到缩放级别0的中心。 *建议:检查getScreenRect(null).getHeight()>0 */ 我选中了getScreenRect(null).getHeight()>0,结果为false 如何以编程方式完成显示布局? 我该怎

我想使用zoomToBoundingBox方法将地图缩放到特定的边界框。
该方法只在缩放级别0上显示地图

在mapView.java源代码中,我发现:

/** *缩放贴图以尽可能靠近指定的边界框。 *必须在显示布局完成后调用,或者屏幕尺寸未知,并且 *将始终缩放到缩放级别0的中心。 *建议:检查getScreenRect(null).getHeight()>0 */

我选中了
getScreenRect(null).getHeight()>0
,结果为false

如何以编程方式完成显示布局?

我该怎么做才能使上面的谓词为true?

我也有同样的问题。我通过在onLayout()方法末尾调用zoomToBoundingBox()调用解决了这个问题

我有自己的MapView子类,用于将我与地图库选项隔离。此类具有clearPoints/addPoint/layoutPoints样式的接口。在layoutPoints()方法中,我从点集合创建逐项覆盖层,并创建存储在类的实例方法中的边界框

public class MyMapView extends MapView {

// The bounding box around all map points
// Used to determine the correct zoom level to show everything
private int minLat = Integer.MAX_VALUE;
private int minLon = Integer.MAX_VALUE;
private int maxLat = Integer.MIN_VALUE;
private int maxLon = Integer.MIN_VALUE;

private BoundingBoxE6 boundingBox;

我的onLayout()覆盖具有:

/* (non-Javadoc)
 * @see org.osmdroid.views.MapView#onLayout(boolean, int, int, int, int)
 */
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
    super.onLayout(arg0, arg1, arg2, arg3, arg4);

    // Now that we have laid out the map view,
    // zoom to any bounding box
    if (this.boundingBox != null) {
        this.zoomToBoundingBox(this.boundingBox);
    }
}

我不确定这是否是最好的方法,但它似乎对我有效(除了缩放似乎有点太远,但这是另一次的问题)。

尝试了此操作,但无法使用MyMapView mapView=(mapView)findViewById(R.id.mapView)创建视图;这对layout.xml文件或创建视图的方式有影响吗?如果我这样做:mapView=(MyMapView)findviewbyd(R.id.mapView);它拒绝执行演员阵容并崩溃。。。!!!我以编程方式创建地图视图(实际上是所有视图)。我认为有一种方法可以使用正确的构造函数定义“MyMapView”,这样IDE就可以在XML中创建MyMapView。但这是很多年前hazy“当我第一次开始使用Android时”读到的。@thanasio2如果您使用
,它应该与您的xml布局一起工作。