bounding the lat lng with osmdroid similar to LatLngBounds in google maps

孤街醉人 提交于 2019-12-04 05:41:54

问题


In my android application I'm using routing and clustering in osmdroid but I'm not able to bound the LatLng like we do in google maps with latlngbounds.builder...

for example

LatLng longlat = new LatLng(lat, log);

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

I want to do the same with osmdroid.


回答1:


Google Maps LatLngBounds becomes BoundingBox in osmdroid (more or less).

It has no direct equivalent to the LatLngBounds.including method (yes, could be a good idea to implement this one).

But BoundingBox.fromGeoPoints covers a lot of needs.




回答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;
            }
        }

This will check whether current location is under bound or not.



来源:https://stackoverflow.com/questions/43757236/bounding-the-lat-lng-with-osmdroid-similar-to-latlngbounds-in-google-maps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!