0

我有一个 MapView,我在上面调用 getController().zoomToSpan()。我对 zoomToSpan() 的问题是我希望在地图图钉之外有一个一致的(例如,15dp)填充,以便可以选择它们而无需用户捏合来缩小。目前我正在使用地图引脚的最小/最大长/纬度填充 zoomToSpan(),因此边缘上的那些不会立即可见或可选择。

我考虑过使用固定的长/纬度填充,但我不能保证地图图钉不会太近或太远。因此,虽然固定的长/纬度填充可能适用于大多数情况,但它不适用于所有情况。

这就是我当前设置 zoomToPan() 的方式:

mapView.getController().zoomToSpan(MapPoint.convertToGeoPoint(Math.abs(fMinLat - fMaxLat)), MapPoint.convertToGeoPoint(Math.abs(fMinLong - fMaxLong)));

这是我对如何设置它的一个想法,但我不确定它是否真的解决了问题,或者是否有更好的方法来做到这一点:

mapView.getController().zoomToSpan(MapPoint.convertToGeoPoint((float) (Math.abs(fMinLat-fMaxLat) + (Math.abs(fMaxLat - fMaxLat)) * 0.5)), MapPoint.convertToGeoPoint((float) (Math.abs(fMinLong-fMaxLong) + (Math.abs(fMinLong - fMaxLong) * 0.5))));

我已经检查了这些问题,但我已经过了让它工作的点;我只是想让它变得优美: zoomToSpan implementation problemCalculating zoomToSpan() degree based on min/max lat/lng to be in the mapView

4

1 回答 1

1

您的解决方案应该可以正常工作。请注意,您在“(Math.abs(fMaxLat - fMaxLat)) * 0.5)”中有错字。您使用了两次“fMaxLat”。

你可以写成更简单的形式:

mapView.getController().zoomToSpan((int)(Math.abs(fMinLat-fMaxLat) * 1.5), (int)(Math.abs(fMinLong-fMaxLong) * 1.5));

然后,您可以尝试 1.0 和 1.99 之间的不同乘法值,看看哪个更能达到您的期望。

Also keep in mind that zoom always change in steps (is not progressive) of powers of 2, meaning it will double the zoom or it will reduce to half. The final result achieved will vary with different points in the map, which can fit closely to a zoom value and very distante from the edge on previous one.

于 2012-10-03T18:22:55.847 回答