我正在使用 osmdroid 奖金包绘制路线。该路线的起点和终点坐标为:-
原点 - 52.24896,0.71795
目的地 - 54.27916,-1.9732
我的代码的相关部分是:-
BoundingBox b = getBoundingBox(origin,destination);
map.setMinZoomLevel(7d); // <<==== Needed to initialise zoom level
map.zoomToBoundingBox(b,false);
map.invalidate();
和
private BoundingBox getBoundingBox(GeoPoint start, GeoPoint end) {
double north;
double south;
double east;
double west;
if(start.getLatitude() > end.getLatitude()) {
north = start.getLatitude();
south = end.getLatitude();
} else {
north = end.getLatitude();
south = start.getLatitude();
}
if(start.getLongitude() > end.getLongitude()) {
east = start.getLongitude();
west = end.getLongitude();
} else {
east = end.getLongitude();
west = start.getLongitude();
}
return new BoundingBox(north, east, south, west);
}
我使用的 map 图 block 的缩放级别为 7-13。
如果没有“setMinZoomLevel”语句,起点/终点标记将以最能描述为深空的缩放级别显示在屏幕的左上角。如果我包含“setMinZoomLevel”,则 map 将显示在该级别,并且不会缩放以适合边界框(应位于级别 8)。我尝试了一条更小的路线,但最终结果完全相同。
我做错了什么?
最佳答案
据了解,需要显示 map ,大概是为了记录屏幕尺寸。因此,答案是首先使用 MapController 作为 onCreate 过程的一部分设置缩放级别,然后在 MapView.OnFirstLayoutListener 中调用 ZoomToBoundingBox。我使用的代码是:-
map.addOnFirstLayoutListener(new MapView.OnFirstLayoutListener() {
public void onFirstLayout(View v, int left, int top, int right, int bottom) {
BoundingBox b = getBoundingBox(origin,destination);
map.zoomToBoundingBox(b,false,100);
map.invalidate();
}
});
关于zooming - osmdroid ZoomToBoundingBox 未缩放到boundingBox 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57258078/