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

Get bounding box on Android #3706

Closed
esisa opened this issue Jan 27, 2016 · 8 comments
Closed

Get bounding box on Android #3706

esisa opened this issue Jan 27, 2016 · 8 comments
Labels
Android Mapbox Maps SDK for Android

Comments

@esisa
Copy link

esisa commented Jan 27, 2016

Is there no way to get the current bounding box on Android? On iOS it seems to be a bounds variable that I can use, but I cannot find anything similar on Android.

@1ec5 1ec5 added the Android Mapbox Maps SDK for Android label Jan 27, 2016
@kristianstorvoll
Copy link

Until they add it, I guess you could try this:

//create bounds
LatLng southWest = mapView.fromScreenLocation(new PointF(0f, mapView.getHeight()));
LatLng northEast = mapView.fromScreenLocation(new PointF(mapView.getWidth(), 0f));
CoordinateBounds bounds = new CoordinateBounds(southWest, northEast);

//set the bounds
mapView.setVisibleCoordinateBounds(bounds, true);

@tobrun
Copy link
Member

tobrun commented Jan 28, 2016

@esisa
Thank you for reaching out, sadly we don't expose this as an API just yet.
I will definitely takes this in mind when landing #3145 and #3602.
The suggestion of @AlPHez is currently the correct way of calculating the bounds for now.
Will close this down in favour of the feature request in above issues.

@tobrun tobrun closed this as completed Jan 28, 2016
@esisa
Copy link
Author

esisa commented Feb 8, 2016

Thanks @AlPHez

@sddamico
Copy link

@tobrun did this work around get lost in 4.0?

@tobrun
Copy link
Member

tobrun commented Jul 14, 2016

@sddamico, since 4.0.0 we changed the naming of CoordinateBounds to LatLngBounds. If you are interested in getting the bounds of current viewport. Take a look at Mapbox.getProjection(). Reach out if you have any other questions!

@sddamico
Copy link

@tobrun yeah, I was specifically referring to setVisibleCoordinateBounds which still seems like there's a jni method but no corresponding java one...

I'm attempting to accomplish something similar to the effect of the api's that might be offered in #3602. The web engineer I am working with was able to achieve the effect of bounding the map by using the options.maxBounds in js.

@tobrun
Copy link
Member

tobrun commented Jul 14, 2016

@sddamico
We expose the following camera update method:

    /**
     * Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude
     * bounds are centered on screen at the greatest possible zoom level.
     * You can specify padding, in order to inset the bounding box from the map view's edges.
     * The returned CameraUpdate has a bearing of 0 and a tilt of 0.
     *
     * @param bounds  Bounds to match Camera position with
     * @param padding Padding added to the bounds
     * @return CameraUpdate Final Camera Position
     */
    public static CameraUpdate newLatLngBounds(@NonNull LatLngBounds bounds, int padding) {
        return newLatLngBounds(bounds, padding, padding, padding, padding);
    }

    /**

Note that we don't restrict the user from navigating outside of the set bounds.
This feature is being tracked in #3602.

@sddamico
Copy link

@tobrun yeah, I definitely need to limit the user from navigating outside the bounds. I'll start investigating some other workarounds.

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

No branches or pull requests

5 participants