Search in sources :

Example 51 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-navigation-android by mapbox.

the class MockNavigationActivity method newOrigin.

private void newOrigin() {
    if (mapboxMap != null) {
        LatLng latLng = Utils.getRandomLatLng(new double[] { -77.1825, 38.7825, -76.9790, 39.0157 });
        ((MockLocationEngine) locationEngine).setLastLocation(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
        mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12));
        mapboxMap.setMyLocationEnabled(true);
        mapboxMap.getTrackingSettings().setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
    }
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng) MockLocationEngine(com.mapbox.services.android.navigation.v5.location.MockLocationEngine)

Example 52 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-navigation-android by mapbox.

the class RerouteActivity method drawRoute.

private void drawRoute(DirectionsRoute route) {
    List<LatLng> points = new ArrayList<>();
    List<Point> coords = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6).coordinates();
    for (Point point : coords) {
        points.add(new LatLng(point.latitude(), point.longitude()));
    }
    if (!points.isEmpty()) {
        if (polyline != null) {
            mapboxMap.removePolyline(polyline);
        }
        // Draw polyline on map
        polyline = mapboxMap.addPolyline(new PolylineOptions().addAll(points).color(Color.parseColor("#4264fb")).width(5));
    }
}
Also used : ArrayList(java.util.ArrayList) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Point(com.mapbox.geojson.Point) PolylineOptions(com.mapbox.mapboxsdk.annotations.PolylineOptions)

Example 53 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-navigation-android by mapbox.

the class NavigationViewActivity method onLocationFound.

private void onLocationFound(Location location) {
    if (!locationFound) {
        animateCamera(new LatLng(location.getLatitude(), location.getLongitude()));
        Snackbar.make(mapView, R.string.explanation_long_press_waypoint, Snackbar.LENGTH_LONG).show();
        locationFound = true;
        hideLoading();
    }
}
Also used : LatLng(com.mapbox.mapboxsdk.geometry.LatLng)

Example 54 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng 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)

Example 55 with LatLng

use of com.mapbox.mapboxsdk.geometry.LatLng in project mapbox-navigation-android by mapbox.

the class DynamicCamera method createCameraPosition.

/**
 * Creates a camera position with the current location and upcoming maneuver location.
 * <p>
 * Using {@link MapboxMap#getCameraForLatLngBounds(LatLngBounds, int[])} with a {@link LatLngBounds}
 * that includes the current location and upcoming maneuver location.
 *
 * @param location      for current location
 * @param routeProgress for upcoming maneuver location
 * @return camera position that encompasses both locations
 */
private CameraPosition createCameraPosition(Location location, RouteProgress routeProgress) {
    LegStep upComingStep = routeProgress.currentLegProgress().upComingStep();
    if (upComingStep != null) {
        Point stepManeuverPoint = upComingStep.maneuver().location();
        List<LatLng> latLngs = new ArrayList<>();
        LatLng currentLatLng = new LatLng(location);
        LatLng maneuverLatLng = new LatLng(stepManeuverPoint.latitude(), stepManeuverPoint.longitude());
        latLngs.add(currentLatLng);
        latLngs.add(maneuverLatLng);
        if (latLngs.size() < 1 || currentLatLng.equals(maneuverLatLng)) {
            return mapboxMap.getCameraPosition();
        }
        LatLngBounds cameraBounds = new LatLngBounds.Builder().includes(latLngs).build();
        int[] padding = { 0, 0, 0, 0 };
        CameraPosition positionForLatLngBounds = mapboxMap.getCameraForLatLngBounds(cameraBounds, padding);
        if (positionForLatLngBounds != null) {
            return positionForLatLngBounds;
        }
    }
    return mapboxMap.getCameraPosition();
}
Also used : CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Point(com.mapbox.geojson.Point) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Aggregations

LatLng (com.mapbox.mapboxsdk.geometry.LatLng)57 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)12 ArrayList (java.util.ArrayList)10 Point (com.mapbox.geojson.Point)7 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)7 MapboxMap (com.mapbox.mapboxsdk.maps.MapboxMap)6 NonNull (android.support.annotation.NonNull)5 PointF (android.graphics.PointF)4 OnMapReadyCallback (com.mapbox.mapboxsdk.maps.OnMapReadyCallback)4 ValueAnimator (android.animation.ValueAnimator)3 MultiLocationEngine (cl.smartcities.isci.transportinspector.map.engine.MultiLocationEngine)3 MultiLayerOnMapClickListener (cl.smartcities.isci.transportinspector.map.utils.MultiLayerOnMapClickListener)3 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)3 Poi (io.jawg.osmcontributor.model.entities.Poi)3 Subscribe (org.greenrobot.eventbus.Subscribe)3 Intent (android.content.Intent)2 Location (android.location.Location)2 View (android.view.View)2 RouteHelper (cl.smartcities.isci.transportinspector.database.RouteHelper)2 BusClickHandler (cl.smartcities.isci.transportinspector.map.model.bus.BusClickHandler)2