com.google.maps.model.SpeedLimit Java Examples
The following examples show how to use
com.google.maps.model.SpeedLimit.
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: SpeedLimitsWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 6 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { String[] placeIds = ((String) workItem.getParameter("PlaceIds")).split(","); try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); SpeedLimit[] speedLimits = RoadsApi.speedLimits(geoApiContext, placeIds).await(); results.put(RESULTS_VALUE, speedLimits); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example #2
Source File: RoadsApiIntegrationTest.java From google-maps-services-java with Apache License 2.0 | 6 votes |
@Test public void testSpeedLimitsWithLatLngs() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(speedLimitsResponse)) { LatLng[] path = new LatLng[] { new LatLng(-33.865382, 151.192861), new LatLng(-33.865837, 151.193376), new LatLng(-33.866745, 151.19373), new LatLng(-33.867128, 151.19344), new LatLng(-33.867547, 151.193676), new LatLng(-33.867841, 151.194137), new LatLng(-33.868224, 151.194116) }; SpeedLimit[] speeds = RoadsApi.speedLimits(sc.context, path).await(); assertNotNull(Arrays.toString(speeds)); assertEquals("/v1/speedLimits", sc.path()); sc.assertParamValue(join('|', path), "path"); assertEquals(7, speeds.length); for (SpeedLimit speed : speeds) { assertNotNull(speed.placeId); assertEquals(40.0, speed.speedLimit, 0.001); } } }
Example #3
Source File: RoadsApiIntegrationTest.java From google-maps-services-java with Apache License 2.0 | 6 votes |
@Test public void testSpeedLimitsWithUsaLatLngs() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(speedLimitsUSAResponse)) { LatLng[] path = new LatLng[] { new LatLng(33.777489, -84.397805), new LatLng(33.777550, -84.395700), new LatLng(33.776900, -84.393110), new LatLng(33.776860, -84.389550), new LatLng(33.775491, -84.388797), new LatLng(33.773250, -84.388840), new LatLng(33.771991, -84.388840) }; SpeedLimit[] speeds = RoadsApi.speedLimits(sc.context, path).await(); assertNotNull(Arrays.toString(speeds)); assertEquals("/v1/speedLimits", sc.path()); sc.assertParamValue(join('|', path), "path"); assertEquals(7, speeds.length); for (SpeedLimit speed : speeds) { assertNotNull(speed.placeId); assertTrue(speed.speedLimit > 0); } } }
Example #4
Source File: RoadsApiIntegrationTest.java From google-maps-services-java with Apache License 2.0 | 6 votes |
@Test public void testSpeedLimitsWithPlaceIds() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext(speedLimitsWithPlaceIdsResponse)) { String[] placeIds = new String[] { "ChIJrfDjZYoE9YgRLpb3bOhcPno", "ChIJyU-E2mEE9YgRftyNXxcfQYw", "ChIJc0BrC2EE9YgR71DvaFzNgrA" }; SpeedLimit[] speeds = RoadsApi.speedLimits(sc.context, placeIds).await(); assertNotNull(Arrays.toString(speeds)); assertEquals("/v1/speedLimits", sc.path()); assertEquals(3, speeds.length); assertEquals("ChIJc0BrC2EE9YgR71DvaFzNgrA", speeds[2].placeId); for (SpeedLimit speed : speeds) { assertTrue(speed.speedLimit > 0); } } }
Example #5
Source File: MainActivity.java From roads-api-samples with Apache License 2.0 | 5 votes |
@Override protected Map<String, SpeedLimit> doInBackground(Void... params) { Map<String, SpeedLimit> placeSpeeds = null; try { placeSpeeds = getSpeedLimits(mContext, mSnappedPoints); publishProgress(0, placeSpeeds.size()); // Generate speed limit icons, with geocoded labels. Set<String> visitedPlaceIds = new HashSet<>(); for (SnappedPoint point : mSnappedPoints) { if (!visitedPlaceIds.contains(point.placeId)) { visitedPlaceIds.add(point.placeId); GeocodingResult geocode = geocodeSnappedPoint(mContext, point); publishProgress(visitedPlaceIds.size()); // As each place has been geocoded, we'll use the name of the place // as the marker title, so tapping the marker will display the address. markers.add(generateSpeedLimitMarker( placeSpeeds.get(point.placeId).speedLimit, point, geocode)); } } } catch (Exception ex) { toastException(ex); ex.printStackTrace(); } return placeSpeeds; }
Example #6
Source File: MainActivity.java From roads-api-samples with Apache License 2.0 | 5 votes |
@Override protected void onPostExecute(Map<String, SpeedLimit> speeds) { for (MarkerOptions marker : markers) { mMap.addMarker(marker); } mProgressBar.setVisibility(View.INVISIBLE); mPlaceSpeeds = speeds; }
Example #7
Source File: MainActivity.java From roads-api-samples with Apache License 2.0 | 5 votes |
/** * Retrieves speed limits for the previously-snapped points. This method is efficient in terms * of quota usage as it will only query for unique places. * * Note: Speed Limit data is only available with an enabled Maps for Work API key. */ private Map<String, SpeedLimit> getSpeedLimits(GeoApiContext context, List<SnappedPoint> points) throws Exception { Map<String, SpeedLimit> placeSpeeds = new HashMap<>(); // Pro tip: save on quota by filtering to unique place IDs for (SnappedPoint point : points) { placeSpeeds.put(point.placeId, null); } String[] uniquePlaceIds = placeSpeeds.keySet().toArray(new String[placeSpeeds.keySet().size()]); // Loop through the places, one page (API request) at a time. for (int i = 0; i < uniquePlaceIds.length; i += PAGE_SIZE_LIMIT) { String[] page = Arrays.copyOfRange(uniquePlaceIds, i, Math.min(i + PAGE_SIZE_LIMIT, uniquePlaceIds.length)); // Execute! SpeedLimit[] placeLimits = RoadsApi.speedLimits(context, page).await(); for (SpeedLimit sl : placeLimits) { placeSpeeds.put(sl.placeId, sl); } } return placeSpeeds; }
Example #8
Source File: RoadsApi.java From google-maps-services-java with Apache License 2.0 | 4 votes |
@Override public SpeedLimit[] getResult() { return speedLimits; }
Example #9
Source File: RoadsApi.java From google-maps-services-java with Apache License 2.0 | 3 votes |
/** * Returns the posted speed limit for given road segments. * * <p>Note: The accuracy of speed limit data returned by the Google Maps Roads API cannot be * guaranteed. Speed limit data provided is not real-time, and may be estimated, inaccurate, * incomplete, and/or outdated. Inaccuracies in our data may be reported through <a * href="https://www.localguidesconnect.com/t5/News-Updates/Exclusive-Edit-a-road-segment-in-Google-Maps/ba-p/149865"> * Google Maps Feedback</a>. * * @param context The {@link GeoApiContext} to make requests through. * @param placeIds The Place ID of the road segment. Place IDs are returned by the {@link * #snapToRoads(GeoApiContext, com.google.maps.model.LatLng...)} method. You can pass up to * 100 placeIds with each request. * @return Returns the speed limits as a {@link PendingResult}. */ public static PendingResult<SpeedLimit[]> speedLimits(GeoApiContext context, String... placeIds) { String[] placeParams = new String[2 * placeIds.length]; int i = 0; for (String placeId : placeIds) { placeParams[i++] = "placeId"; placeParams[i++] = placeId; } return context.get(SPEEDS_API_CONFIG, SpeedsResponse.class, placeParams); }
Example #10
Source File: RoadsApi.java From google-maps-services-java with Apache License 2.0 | 2 votes |
/** * Returns the posted speed limit for given road segments. The provided LatLngs will first be * snapped to the most likely roads the vehicle was traveling along. * * <p>Note: The accuracy of speed limit data returned by the Google Maps Roads API cannot be * guaranteed. Speed limit data provided is not real-time, and may be estimated, inaccurate, * incomplete, and/or outdated. Inaccuracies in our data may be reported through <a * href="https://www.localguidesconnect.com/t5/News-Updates/Exclusive-Edit-a-road-segment-in-Google-Maps/ba-p/149865"> * Google Maps Feedback</a>. * * @param context The {@link GeoApiContext} to make requests through. * @param path The collected GPS points as a path. * @return Returns the speed limits as a {@link PendingResult}. */ public static PendingResult<SpeedLimit[]> speedLimits(GeoApiContext context, LatLng... path) { return context.get(SPEEDS_API_CONFIG, SpeedsResponse.class, "path", join('|', path)); }