【问题标题】:Need to Check if a particular location is within the boundaries of the map需要检查特定位置是否在地图的边界内
【发布时间】:2012-02-27 23:54:42
【问题描述】:

我使用 osmdroid MapView。 我需要确定用户位置是否在地图边界内(取决于缩放级别)。

我尝试使用 MapView.getBoundingBox().contain(location).. 但似乎 getBoundingBox() 返回可见边界。

有没有办法获得原始地图边界(取决于缩放级别)?

谢谢

【问题讨论】:

    标签: android android-mapview osmdroid


    【解决方案1】:

    可以查到西北角和东南角的经纬度 您的地图视图的代码如下:

    GeoPoint topLeftGpt     = (GeoPoint) mapView.getProjection().fromPixels(0, 0);
    GeoPoint bottomRightGpt = (GeoPoint) mapView.getProjection().fromPixels(
                mapView.getWidth(), mapView.getHeight());
    

    然后您可以确定兴趣点是否在这些范围内。

    【讨论】:

      【解决方案2】:

      对于 v2:

          LatLng northwest  = (LatLng) mMap.getProjection().fromScreenLocation(new Point(0, 0));
          LatLng southeast = (LatLng) mGoogleMap.getProjection().fromScreenLocation(
              new Point(mMapView.getWidth(), mMapView.getHeight()));
      

      【讨论】:

        猜你喜欢
        • 2014-06-11
        • 2015-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-11
        • 2011-04-08
        相关资源
        最近更新 更多