【问题标题】:Adding padding to MapViewController.zoomToSpan()向 MapViewController.zoomToSpan() 添加填充
【发布时间】:2012-10-04 02:30:53
【问题描述】:

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

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

这就是我当前设置 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() degrees based on min/max lat/lng to be in the mapView

【问题讨论】:

    标签: java android google-maps


    【解决方案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 之间的不同乘法值,看看哪个更能达到您的期望。

    另外请记住,缩放总是以 2 的幂的步长(不是渐进的)变化,这意味着它会将缩放加倍或缩小到一半。最终得到的结果会随着地图中不同点的不同而不同,这可以与缩放值非常接近,而与之前的边缘很远。

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 2011-12-15
      • 2019-07-31
      • 1970-01-01
      • 2020-11-20
      • 2012-02-06
      • 2015-02-12
      • 2015-08-14
      • 2013-12-13
      相关资源
      最近更新 更多