Search in sources :

Example 1 with InvalidLatLngBoundsException

use of com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException in project mapbox-navigation-android by mapbox.

the class NavigationViewActivity method boundCameraToRoute.

public void boundCameraToRoute() {
    if (route != null) {
        List<Point> routeCoords = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6).coordinates();
        List<LatLng> bboxPoints = new ArrayList<>();
        for (Point point : routeCoords) {
            bboxPoints.add(new LatLng(point.latitude(), point.longitude()));
        }
        if (bboxPoints.size() > 1) {
            try {
                LatLngBounds bounds = new LatLngBounds.Builder().includes(bboxPoints).build();
                // left, top, right, bottom
                int topPadding = launchBtnFrame.getHeight() * 2;
                animateCameraBbox(bounds, CAMERA_ANIMATION_DURATION, new int[] { 50, topPadding, 50, 100 });
            } catch (InvalidLatLngBoundsException exception) {
                Toast.makeText(this, R.string.error_valid_route_not_found, Toast.LENGTH_SHORT).show();
            }
        }
    }
}
Also used : InvalidLatLngBoundsException(com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Point(com.mapbox.geojson.Point)

Aggregations

Point (com.mapbox.geojson.Point)1 InvalidLatLngBoundsException (com.mapbox.mapboxsdk.exceptions.InvalidLatLngBoundsException)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 ArrayList (java.util.ArrayList)1