【问题标题】:bounding the lat lng with osmdroid similar to LatLngBounds in google maps使用 osmdroid 限定 lat lng,类似于谷歌地图中的 LatLngBounds
【发布时间】:2017-05-03 10:16:55
【问题描述】:

在我的 android 应用程序中,我在 osmdroid 中使用路由和集群,但我无法像在谷歌地图中使用 latlngbounds.builder 那样绑定 LatLng...

例如

LatLng longlat = new LatLng(lat, log);

LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(longlat);

我想对 osmdroid 做同样的事情。

【问题讨论】:

  • 你说的是osmdroid吗?请至少提及您正在使用的库。
  • 是的,我说的是 osmdroid

标签: android osmdroid


【解决方案1】:

Google Maps LatLngBounds 成为 osmdroid 中的 BoundingBox(或多或少)。

它没有直接等效于 LatLngBounds.include 方法(是的,实现这个方法可能是个好主意)。

但 BoundingBox.fromGeoPoints 涵盖了很多需求。

【讨论】:

    【解决方案2】:
    { 
    IGeoPoint screenTopLeft = mapView.getProjection().fromPixels(0, 0);
                IGeoPoint screenTopRight = mapView.getProjection().fromPixels(mapView.getWidth(), 0);
                IGeoPoint screenBottomLeft = mapView.getProjection().fromPixels(0, mapView.getHeight());
                List<IGeoPoint> iGeoPoints = new ArrayList<>();
                iGeoPoints.add(screenTopRight);
                iGeoPoints.add(screenTopLeft);
                iGeoPoints.add(screenBottomLeft);
                BoundingBox boundingBox = BoundingBox.fromGeoPoints(iGeoPoints);
                if (boundingBox.contains(currentLocation.getLatitude(), currentLocation.getLongitude())) {
                    return true;
                } else {
                    return false;
                }
            }
    

    这将检查当前位置是否在边界内。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多