Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[Android] Get visible bounds #3863

Closed
mpuchala opened this issue Feb 9, 2016 · 5 comments
Closed

[Android] Get visible bounds #3863

mpuchala opened this issue Feb 9, 2016 · 5 comments
Labels
Android Mapbox Maps SDK for Android support

Comments

@mpuchala
Copy link

mpuchala commented Feb 9, 2016

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!

@tobrun tobrun added Android Mapbox Maps SDK for Android support labels Feb 9, 2016
@tobrun tobrun added this to the android-v4.0.0 milestone Feb 9, 2016
@tobrun
Copy link
Member

tobrun commented Feb 9, 2016

@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.

@OnlyInAmerica
Copy link

Awesome! Much Thanks!

@donkii
Copy link

donkii commented Apr 4, 2019

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

@tobrun
Copy link
Member

tobrun commented Apr 4, 2019

Projection#getVisibleRegion

@DmitriyYakovlev
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android support
Projects
None yet
Development

No branches or pull requests

5 participants