【问题标题】:Android Map Zoom Level for Current Location and Destination当前位置和目的地的 Android 地图缩放级别
【发布时间】:2013-03-12 01:44:07
【问题描述】:

我正在使用 Google 地图、MappingOverlayActivity 和 ItemizedOverlay 显示用户的当前位置和他们的预定目的地。

首先设置适当的缩放级别的最佳方法是什么,以便两个位置都显示在屏幕上的地图上,地图覆盖的最大区域,即,而不是当前位置在中心,有中心位于 2 点的中间。此外,当用户的当前位置发生变化时,我该如何重新计算和重置适当的缩放级别以合并新的当前位置。

【问题讨论】:

    标签: android android-mapview


    【解决方案1】:

    您使用来自MapController 的方法(您使用mapView.getController() 获得)。

    特别是animateTo(或moveTo)和zoomToSpan

    假设您有两个 GeoPoints

    GeoPoint current;
    GeoPoint destination;
    

    做这样的事情

    mapController.zoomToSpan(Math.abs(current.getLatitudeE6() - destination.getLatitudeE6()), Math.abs(current.getLongitudeE6() - destination.getLongitudeE6());
    mapController.animateTo(new GeoPoint((current.getLatitudeE6() + destination.getLatitudeE6())/2, (current.getLongitudeE6() + destination.getLongitudeE6())/2));
    

    因此您可以计算点的跨度(差异)和中心(平均值)。

    【讨论】:

    • 我是否错过了 animateTo() 参数为 int 的方法,因为我找不到它。
    【解决方案2】:

    对于坐标的中心,您可能需要做一些数学运算 http://en.wikipedia.org/wiki/Centroid

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 2013-12-31
      • 2011-08-23
      • 2011-08-25
      相关资源
      最近更新 更多