use of com.mapbox.geojson.Point 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.geojson.Point 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();
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class NavigationCamera method animateCameraFromLocation.
/**
* Creates an animation with the given {@link RouteInformation#location()}.
* <p>
* This animation that fires for new progress update.
*
* @param routeInformation with location data
*/
private void animateCameraFromLocation(RouteInformation routeInformation) {
Camera cameraEngine = navigation.getCameraEngine();
Point targetPoint = cameraEngine.target(routeInformation);
LatLng target = new LatLng(targetPoint.latitude(), targetPoint.longitude());
double bearing = cameraEngine.bearing(routeInformation);
float tilt = (float) cameraEngine.tilt(routeInformation);
double zoom = cameraEngine.zoom(routeInformation);
CameraPosition position = new CameraPosition.Builder().target(target).bearing(bearing).tilt(tilt).zoom(zoom).build();
easeMapCameraPosition(position);
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class NavigationCamera method animateCameraFromRoute.
/**
* Creates an initial animation with the given {@link RouteInformation#route()}.
* <p>
* This is the first animation that fires prior to receiving progress updates.
* <p>
* If a user interacts with the {@link MapboxMap} while the animation is in progress,
* the animation will be cancelled. So it's important to add the {@link ProgressChangeListener}
* in both onCancel() and onFinish() scenarios.
*
* @param routeInformation with route data
*/
private void animateCameraFromRoute(RouteInformation routeInformation) {
Camera cameraEngine = navigation.getCameraEngine();
Point targetPoint = cameraEngine.target(routeInformation);
LatLng targetLatLng = new LatLng(targetPoint.latitude(), targetPoint.longitude());
double bearing = cameraEngine.bearing(routeInformation);
double zoom = cameraEngine.zoom(routeInformation);
CameraPosition position = new CameraPosition.Builder().target(targetLatLng).bearing(bearing).zoom(zoom).build();
updateMapCameraPosition(position, new MapboxMap.CancelableCallback() {
@Override
public void onCancel() {
navigation.addProgressChangeListener(progressChangeListener);
}
@Override
public void onFinish() {
navigation.addProgressChangeListener(progressChangeListener);
}
});
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class NavigationLauncher method extractCoordinates.
/**
* Used to extract the origin and position coordinates used to launch
* the drop-in UI.
* <p>
* A {@link HashMap} is used to ensure the correct coordinate is
* extracted in the {@link NavigationView} with the defined constants.
*
* @param context to retrieve {@link SharedPreferences}
* @return map with both origin and destination coordinates
*/
static HashMap<String, Point> extractCoordinates(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
double originLng = Double.longBitsToDouble(preferences.getLong(NavigationConstants.NAVIGATION_VIEW_ORIGIN_LNG_KEY, 0));
double originLat = Double.longBitsToDouble(preferences.getLong(NavigationConstants.NAVIGATION_VIEW_ORIGIN_LAT_KEY, 0));
double destinationLng = Double.longBitsToDouble(preferences.getLong(NavigationConstants.NAVIGATION_VIEW_DESTINATION_LNG_KEY, 0));
double destinationLat = Double.longBitsToDouble(preferences.getLong(NavigationConstants.NAVIGATION_VIEW_DESTINATION_LAT_KEY, 0));
Point origin = Point.fromLngLat(originLng, originLat);
Point destination = Point.fromLngLat(destinationLng, destinationLat);
HashMap<String, Point> coordinates = new HashMap<>();
coordinates.put(NavigationConstants.NAVIGATION_VIEW_ORIGIN, origin);
coordinates.put(NavigationConstants.NAVIGATION_VIEW_DESTINATION, destination);
return coordinates;
}
Aggregations