com.google.maps.DirectionsApi Java Examples
The following examples show how to use
com.google.maps.DirectionsApi.
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: RecommendedRouteFragment.java From rox-android with Apache License 2.0 | 6 votes |
@Override public Pair<Poi[], DirectionsRoute> call() throws Exception { Poi[] nextPois = poisApi.awaitRoute(seed.getFoursquareId()); List<Poi> pois = new ArrayList<>(); pois.add(seed); pois.addAll(Arrays.asList(nextPois)); String[] waypoints = new String[pois.size()-1]; for (int i = 0; i < waypoints.length; i++) waypoints[i] = toGoogleMapsServicesLatLng(pois.get(i).getLocation()); DirectionsRoute[] routes = DirectionsApi.newRequest(geoApiContext) .origin(toGoogleMapsServicesLatLng(origin)) .destination(toGoogleMapsServicesLatLng(pois.get(pois.size()-1).getLocation())) .mode(travelMode) .waypoints(waypoints) .await(); return new Pair(nextPois, routes == null || routes.length == 0 ? null : routes[0]); }
Example #3
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 #4
Source File: Directions.java From FXMaps with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates a new {@code Directions} object instance. * * @param key the {@link ApiKey} to use with the application. * @throws IllegalArgumentException when api key presents a problem. */ private Directions(ApiKey key) { try { request = DirectionsApi.newRequest(key.context()); }catch(Exception e) { throw new IllegalArgumentException(e); } }
Example #5
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); } }
Example #6
Source File: RecommendedRouteFragment.java From rox-android with Apache License 2.0 | 4 votes |
@Override public DirectionsRoute call() throws Exception { String[] waypoints = new String[pois.size()-1]; for (int i = 0; i < waypoints.length; i++) waypoints[i] = toGoogleMapsServicesLatLng(pois.get(i).getLocation()); DirectionsRoute[] routes = DirectionsApi.newRequest(geoApiContext) .origin(toGoogleMapsServicesLatLng(origin)) .destination(toGoogleMapsServicesLatLng(pois.get(pois.size()-1).getLocation())) .mode(travelMode) .waypoints(waypoints) .await(); return routes == null || routes.length == 0 ? null : routes[0]; }