gpt4 book ai didi

Android zoomToSpan for MapsForge map

转载 作者:行者123 更新时间:2023-11-29 21:52:19 26 4
gpt4 key购买 nike

MapsForge map 是否存在 zoomToSpan 方法?如果不存在,我该如何实现?有没有一些代码示例或算法描述?

提前致谢

最佳答案

您可以使用以下方法扩展 MapView(MapsForge 版本 0.3.1):

public synchronized void fitToBoundingBox(final BoundingBox pBoundingBox, final int pMaximumZoom) {
int width = this.getWidth();
int height = this.getHeight();
if (width <= 0 || height <= 0) {
this.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
MapView.this.getViewTreeObserver().removeGlobalOnLayoutListener(this);
fitToBoundingBox(pBoundingBox, pMaximumZoom);
}
});
} else {
Projection projection1 = this.getProjection();
GeoPoint pointSouthWest = new GeoPoint(pBoundingBox.minLatitude, pBoundingBox.minLongitude);
GeoPoint pointNorthEast = new GeoPoint(pBoundingBox.maxLatitude, pBoundingBox.maxLongitude);
Point pointSW = new Point();
Point pointNE = new Point();
byte maxLvl = (byte) Math.min(pMaximumZoom, this.getMapZoomControls().getZoomLevelMax());
byte zoomLevel = 0;
while (zoomLevel < maxLvl) {
byte tmpZoomLevel = (byte) (zoomLevel + 1);
projection1.toPoint(pointSouthWest, pointSW, tmpZoomLevel);
projection1.toPoint(pointNorthEast, pointNE, tmpZoomLevel);
if (pointNE.x - pointSW.x > width) {
break;
}
if (pointSW.y - pointNE.y > height) {
break;
}
zoomLevel = tmpZoomLevel;
}
this.getMapViewPosition().setMapPosition(new MapPosition(pBoundingBox.getCenterPoint(), zoomLevel));
}
}

很可能您有一组应该显示在 map 上的叠加层。您必须找到经度和纬度的“最小”和“最大”值,然后调用上面的方法:

mapView.fitToBoundingBox(new BoundingBox(minLat, minLng, maxLat, maxLng), 20);

已经找到这个解决方案here

关于Android zoomToSpan for MapsForge map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14094866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com