我有一个 MapView,我在它上面调用 getController().zoomToSpan() 。我对 ZoomToSpan() 的问题是,我希望在 map 图钉之外有一致的(例如 15dp)填充,以便可以选择它们而不需要用户捏合缩小。目前,我正在使用 map 图钉的最小/最大长/纬度填充 ZoomToSpan(),因此边缘上的图钉不能立即可见或可选择。
我考虑过使用固定的长/纬度填充,但我不能保证 map 图钉不会彼此太近或太远。因此,虽然固定的长/纬度填充可能适用于大多数情况,但它并不适用于所有情况。
这就是我当前设置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 problem ,和Calculating zoomToSpan() degrees based on min/max lat/lng to be in the mapView .
最佳答案
您的解决方案应该可以正常工作。请注意,“(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 之间的不同乘数值,看看哪个更能达到您的期望。
另请记住,缩放始终以 2 的幂为步长(不是渐进)变化,这意味着缩放将加倍或减少到一半。最终获得的结果会随着 map 中不同点的不同而变化,这些点可能与某个缩放值非常接近,但与前一个点的边缘距离很远。
关于java - 向 MapViewController.zoomToSpan() 添加填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12693370/