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);
}
}
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));
}
}
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();
}
}
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();
}
}
}
}
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();
}
Aggregations