com.google.maps.model.DirectionsRoute Java Examples
The following examples show how to use
com.google.maps.model.DirectionsRoute.
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 |
private void onAcquireRoute(DirectionsRoute route) { this.route = route; if (route != null) { double totalDistance = 0f; for (DirectionsLeg leg : route.legs) totalDistance += leg.distance.inMeters; travelDistanceTextView.setText(getString(R.string.travel_distance, totalDistance / 1_000f)); travelDistanceContainer.setVisibility(View.VISIBLE); List<com.google.maps.model.LatLng> polyline = route.overviewPolyline.decodePath(); PolylineOptions pathOptions = new PolylineOptions().color(getResources().getColor(R.color.accent)); for (com.google.maps.model.LatLng point : polyline) pathOptions.add(new LatLng(point.lat, point.lng)); googleMap.addPolyline(pathOptions); } else { Toast.makeText(getActivity().getApplicationContext(), R.string.unavailable_route, Toast.LENGTH_SHORT).show(); } }
Example #3
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 #4
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 #5
Source File: RecommendedRouteFragment.java From rox-android with Apache License 2.0 | 4 votes |
@Override protected void onSuccess(Pair<Poi[], DirectionsRoute> objects) throws Exception { super.onSuccess(objects); onAcquiredNextPois(objects._0); onAcquiredRoute(objects._1); }
Example #6
Source File: RecommendedRouteFragment.java From rox-android with Apache License 2.0 | 4 votes |
private void onAcquiredRoute(DirectionsRoute route) { onAcquireRoute(route); }
Example #7
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]; }
Example #8
Source File: RecommendedRouteFragment.java From rox-android with Apache License 2.0 | 4 votes |
@Override protected void onSuccess(DirectionsRoute route) throws Exception { super.onSuccess(route); onAcquireRoute(route); }