com.google.maps.DirectionsApiRequest Java Examples
The following examples show how to use
com.google.maps.DirectionsApiRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultPathService.java From Real-Time-Taxi-Dispatch-Simulator with MIT License | 6 votes |
@Override public String getCoordinatesFromGoogleAsPolyline(DirectionInput directionInput) { final GeoApiContext context = new GeoApiContext() .setApiKey(environment.getRequiredProperty("gpsSimmulator.googleApiKey")); final DirectionsApiRequest request = DirectionsApi.getDirections( context, directionInput.getFrom(), directionInput.getTo()); try { DirectionsRoute[] routes = request.await(); return routes[0].overviewPolyline.getEncodedPath(); } catch (Exception e) { throw new IllegalStateException(e); } }
Example #2
Source File: DefaultPathService.java From Real-Time-Taxi-Dispatch-Simulator with MIT License | 5 votes |
@Override public List<Point> getCoordinatesFromGoogle(DirectionInput directionInput) { final GeoApiContext context = new GeoApiContext() .setApiKey(environment.getRequiredProperty("gpsSimmulator.googleApiKey")); final DirectionsApiRequest request = DirectionsApi.getDirections( context, directionInput.getFrom(), directionInput.getTo()); List<LatLng> latlongList = null; try { DirectionsRoute[] routes = request.await(); for (DirectionsRoute route : routes) { latlongList = route.overviewPolyline.decodePath(); } } catch (Exception e) { throw new IllegalStateException(e); } final List<Point> points = new ArrayList<>(latlongList.size()); for (LatLng latLng : latlongList) { points.add(new Point(latLng.lat, latLng.lng)); } return points; }
Example #3
Source File: DirectionsWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { String origin = (String) workItem.getParameter("Origin"); String destination = (String) workItem.getParameter("Destination"); String mode = (String) workItem.getParameter("Mode"); String avoid = (String) workItem.getParameter("Avoid"); String units = (String) workItem.getParameter("Units"); try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); DirectionsApiRequest directionsApiRequest = DirectionsApi.newRequest(geoApiContext); directionsApiRequest = directionsApiRequest.origin(origin); directionsApiRequest = directionsApiRequest.destination(destination); if (mode != null) { switch (mode) { case "driving": directionsApiRequest = directionsApiRequest.mode(TravelMode.DRIVING); break; case "walking": directionsApiRequest = directionsApiRequest.mode(TravelMode.WALKING); break; case "bicycling": directionsApiRequest = directionsApiRequest.mode(TravelMode.BICYCLING); break; case "transit": directionsApiRequest = directionsApiRequest.mode(TravelMode.TRANSIT); break; default: directionsApiRequest = directionsApiRequest.mode(TravelMode.DRIVING); } } if (avoid != null) { switch (avoid) { case "tolls": directionsApiRequest = directionsApiRequest.avoid(DirectionsApi.RouteRestriction.TOLLS); break; case "highways": directionsApiRequest = directionsApiRequest.avoid(DirectionsApi.RouteRestriction.HIGHWAYS); break; case "ferries": directionsApiRequest = directionsApiRequest.avoid(DirectionsApi.RouteRestriction.FERRIES); break; default: } } if (units != null) { switch (units) { case "metric": directionsApiRequest = directionsApiRequest.units(Unit.METRIC); break; case "imperial": directionsApiRequest = directionsApiRequest.units(Unit.IMPERIAL); break; default: directionsApiRequest = directionsApiRequest.units(Unit.METRIC); } } DirectionsResult directionsResult = directionsApiRequest.await(); results.put(RESULTS_VALUE, directionsResult); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }