【问题标题】:Function getMapCenter in MapFragment / get MapView from MapFragmentMapFragment 中的函数 getMapCenter / 从 MapFragment 中获取 MapView
【发布时间】:2013-01-31 20:39:56
【问题描述】:

我的 Android 应用中有一个 MapFragment,现在我想知道实际地图上显示的最小和最大纬度/经度。

我找到了这个解决方案:

如果您想找出 MapView 角落的经度纬度,您可以使用:

Point mapCenter = mapView.getMapCenter();
int latitudeSpan = mapView.getLatitudeSpan() / 2;
int longitudeSpan = mapView.getLongitudeSpan() / 2;
int topLeftLat = mapCenter.getLatitudeE6() + (latitudeSpan);
int topLeftLon = mapCenter.getLongitudeE6() - (longitudeSpan);
int bottomLeftLat = mapCenter.getLatitudeE6() - (latitudeSpan);
int bottomLeftLon = mapCenter.getLongitudeE6() + (longitudeSpan);

我现在的问题是我没有 MapView, 我只有一个 GoogleMap (com.google.android.gms.maps.GoogleMap) 和一个 MapFragment (com.google.android.gms.maps.MapFragment)。

我需要最小/最大坐标来执行数据库查询以选择 POI-DB-Entrys。

【问题讨论】:

    标签: android android-mapview google-maps-android-api-2 mapfragment


    【解决方案1】:

    您可以使用来自ProjectiongetVisibleRegion 从您的GoogleMap 获取它。

    假设您将您的 GoogleMap 命名为 map,您会这样做

    VisibleRegion bounds = map.getProjection().getVisibleRegion();
    

    VisibleRegion 不一定是矩形,但可以为您提供边界,请参阅docs 了解更多信息。

    【讨论】:

    • 谢谢,我晚上试试。看起来这就是我搜索的内容。
    【解决方案2】:

    要添加到 iagreen 的答案,您可能对可见区域调用上的 LatLngBounds 感兴趣。

    LatLngBounds bounds = this.mMap.getProjection().getVisibleRegion().latLngBounds;
    

    从中,您可以获得最小/最大纬度/经度(东北/西南角)。

    不确定您要对此做什么,但如果您想检查标记是否“在屏幕上”,那么您可能对 this answer 感兴趣

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 2013-02-28
      • 2013-02-20
      • 2012-11-24
      • 1970-01-01
      • 2014-12-22
      相关资源
      最近更新 更多