com.google.maps.ImageResult Java Examples
The following examples show how to use
com.google.maps.ImageResult.
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: ArmeriaPendingResult.java From curiostack with MIT License | 5 votes |
private T parseResponse(AggregatedHttpResponse message) throws ApiException, IOException { HttpStatus status = message.status(); String contentType = message.headers().get(HttpHeaderNames.CONTENT_TYPE); if (contentType != null && contentType.startsWith("image") && responseClass == ImageResult.Response.class && status.equals(HttpStatus.OK)) { var result = new ImageResult(contentType, message.content().array()); @SuppressWarnings("unchecked") T castResult = (T) result; return castResult; } final R resp; try { resp = gson.fromJson(message.contentUtf8(), responseClass); } catch (JsonSyntaxException e) { if (!status.codeClass().equals(HttpStatusClass.SUCCESS)) { // Some of the APIs return 200 even when the API request fails, as long as the transport // mechanism succeeds. In these cases, INVALID_RESPONSE, etc are handled by the Gson // parsing. throw new IOException( String.format("Server Error: %d %s", status.code(), status.reasonPhrase())); } // Otherwise just cough up the syntax exception. throw e; } if (resp.successful()) { return resp.getResult(); } else { // TODO(choko): Retry on retryable exceptions ideally without implementing retry business // logic itself. throw resp.getError(); } }
Example #2
Source File: StaticMapsWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { String width = (String) workItem.getParameter("Width"); String height = (String) workItem.getParameter("Height"); String centerLocation = (String) workItem.getParameter("CenterLocation"); String zoom = (String) workItem.getParameter("Zoom"); String scale = (String) workItem.getParameter("Scale"); String mapType = (String) workItem.getParameter("MapType"); String markers = (String) workItem.getParameter("Markers"); try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); StaticMapsRequest staticMapsRequest = StaticMapsApi.newRequest(geoApiContext, new Size(Integer.parseInt(width), Integer.parseInt(height))); staticMapsRequest.center(centerLocation); if (zoom != null) { staticMapsRequest = staticMapsRequest.zoom(Integer.parseInt(zoom)); } if (scale != null) { staticMapsRequest = staticMapsRequest.scale(Integer.parseInt(scale)); } if (mapType != null) { staticMapsRequest = staticMapsRequest.maptype(StaticMapsRequest.StaticMapType.valueOf(mapType)); } if (markers != null) { // markers format: color,label,location;color,label,location .... String[] markersArray = markers.split(";"); for (String newMarker : markersArray) { String[] newMarkerInfo = newMarker.split(","); StaticMapsRequest.Markers staticMarker = new StaticMapsRequest.Markers(); staticMarker.color(newMarkerInfo[0]); staticMarker.label(newMarkerInfo[1]); staticMarker.addLocation(newMarkerInfo[2]); staticMapsRequest = staticMapsRequest.markers(staticMarker); } } ImageResult imageResult = staticMapsRequest.await(); results.put(RESULTS_VALUE, imageResult); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }