/** @param event */ public void onMapClick(MapClickEvent event) { LatLng e = event.getLatLng(); if (e == null) { e = event.getOverlayLatLng(); // if(mState == State.Default) // { // MapItemOverlay mio = (MapItemOverlay) event.getOverlay(); // HasCoordinates item = mio.getMapItem(); // if(item instanceof MapItem) // showMapItemEdit((MapItem)item); // } } if (mState == State.Adding || mState == State.Editing) { mDataModel.getX().setValue(e.getLongitude()); mDataModel.getY().setValue(e.getLatitude()); mDisplay.getStreetView().setLocation(e); handleChangePosition(e); } else if (mState == State.AddingStar) { Star s = new Star(); s.setType(mStarType); s.setX(e.getLongitude()); s.setY(e.getLatitude()); onFinishAddingStar(s); } }
public static void handleDevMapClick(LatLng position) { if (WindowInformation.locationPanel.isRoadMode()) { if (location1ID != -1 && position != null) { roadPoints.add(position); // Window.alert("Road point added"); } } else { String locationName = Window.prompt("Name for this location:", "NULL" + locationCounter++); if (locationName != null) { GameServices.devService.createLocation( GameInfo.getInstance().getPlayer(), locationName, position.getLatitude(), position.getLongitude(), new AsyncCallback<Void>() { public void onFailure(Throwable caught) {} public void onSuccess(Void result) { // TODO: Keep the auto-refresh when creating locations? // GameInformation.getInstance().refreshAll(true); } }); } } }
private static CoordinateBounds getSearchBounds(double radius) { LocationManager locationManager = MobileApplicationContext.getLocationManager(); LatLng p = locationManager.getCurrentSearchLocation(); CoordinateBounds bounds = SphericalGeometryLibrary.bounds(p.getLatitude(), p.getLongitude(), radius); System.out.println(bounds); return bounds; }
/** Handle a map click event */ public void onClick(final MapClickEvent e) { final MapWidget sender = e.getSender(); final Overlay overlay = e.getOverlay(); final LatLng point = e.getLatLng(); if (overlay != null && overlay instanceof Marker) { // clear a marker that has been clicked on sender.removeOverlay(overlay); } else { // clear the last-placed marker ... if (_lastMarker != null && _lastMarker instanceof Marker) { sender.removeOverlay(_lastMarker); _lastMarker = null; } // ... and add the new marker final Marker mark = new Marker(point); _lastMarker = mark; sender.addOverlay(mark); // set the location new GeoFixAsyncCallback(point.getLatitude(), point.getLongitude()).execute(); } }
private void setPosition( ExtSensor positionSensor, final List<ExtDevice> devices, final int index, final String name, final int floors, final Polygon outline, final List<ExtSensor> sensors) { ExtDevice device = devices.get(index); LatLng latLng = device.<LatLng>get("latlng"); // prepare request properties final Method method = RequestBuilder.POST; final UrlBuilder urlBuilder = new UrlBuilder() .setProtocol(CommonSenseClient.Urls.PROTOCOL) .setHost(CommonSenseClient.Urls.HOST); urlBuilder.setPath(Urls.PATH_SENSORS + "/" + positionSensor.getId() + "/data.json"); final String url = urlBuilder.buildString(); final String sessionId = SessionManager.getSessionId(); String value = "{\\\"latitude\\\":" + latLng.getLatitude() + ",\\\"longitude\\\":" + latLng.getLongitude() + ",\\\"provider\\\":\\\"environment\\\"}"; String body = "{\"data\":["; body += "{\"value\":\"" + value + "\",\"date\":" + NumberFormat.getFormat("#.#").format(System.currentTimeMillis() / 1000) + "}"; body += "]}"; // prepare request callback RequestCallback reqCallback = new RequestCallback() { @Override public void onError(Request request, Throwable exception) { LOG.warning("POST position onError callback: " + exception.getMessage()); onSetPositionFailure(); } @Override public void onResponseReceived(Request request, Response response) { LOG.finest("POST position response received: " + response.getStatusText()); int statusCode = response.getStatusCode(); if (Response.SC_CREATED == statusCode) { onSetPositionSuccess( response.getText(), devices, index, name, floors, outline, sensors); } else { LOG.warning("POST position returned incorrect status: " + statusCode); onSetPositionFailure(); } } }; // send request try { RequestBuilder builder = new RequestBuilder(method, url); builder.setHeader("X-SESSION_ID", sessionId); builder.setHeader("Content-Type", "application/json"); builder.sendRequest(body, reqCallback); } catch (Exception e) { LOG.warning("POST position request threw exception: " + e.getMessage()); reqCallback.onError(null, e); } }
private void assertEquals(LatLng ll1, LatLng ll2) { assertEquals(ll1.getLatitude(), ll2.getLatitude()); assertEquals(ll1.getLongitude(), ll2.getLongitude()); }