mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

[Android] Get visible bounds

Open mpuchala opened this issue 10 years ago • 5 comments

Guys,

Is is possible to get visible bounds? I haven't find any suitable method. I know how to set it (setVisibleCoordinateBounds) but getter would be also very useful. Maybe a workaround is to compute it using center point and zoom, but it doesn't look nice...

Thanks in advance!

mpuchala avatar Feb 09 '16 11:02 mpuchala

@mpuchala, thank you for reaching out

getVisibleBounds is currently not a getter we support but you can use this workaround:

int viewportWidth = mMapView.getWidth();
int viewportHeight = mMapView.getHeight();

LatLng topLeft = mMapView.fromScreenLocation(new PointF(0, 0));
LatLng topRight = mMapView.fromScreenLocation(new PointF(viewportWidth, 0));
LatLng bottomRight = mMapView.fromScreenLocation(new PointF(viewportWidth, viewportHeight));
LatLng bottomLeft = mMapView.fromScreenLocation(new PointF(0, viewportHeight));

You can then feed these values in a VisibleCoordinateBounds in the 3.2.0 release. For the 4.0.0 we are thinking about exposing this as Google Maps SDK is exposing in #3758.

Reach out if you have any other questions.

tobrun avatar Feb 09 '16 11:02 tobrun

Awesome! Much Thanks!

OnlyInAmerica avatar Mar 12 '16 02:03 OnlyInAmerica

Cannot find the new way of getting the visible bounds, has it been released yet or should we continue using the example above.

donkii avatar Apr 04 '19 12:04 donkii

Projection#getVisibleRegion

tobrun avatar Apr 04 '19 13:04 tobrun

val bounds: LatLngBounds = mapboxMap.projection.visibleRegion.latLngBounds

DmitriyYakovlev avatar Feb 01 '21 21:02 DmitriyYakovlev