List of usage examples for com.google.gwt.geolocation.client Geolocation getCurrentPosition
public void getCurrentPosition(Callback<Position, PositionError> callback)
From source file:$.ZoomToLocationController.java
License:Open Source License
public void onMouseUp(MouseUpEvent event) { // StyleElement se = (StyleElement) Document.get().getElementById("inlineStyle"); // se.setInnerText(".msRibbon { background: green; }"); final Geolocation geo = Geolocation.getIfSupported(); if (geo != null) { geo.getCurrentPosition(new Callback<Position, PositionError>() { @Override//from ww w . j a v a 2 s.c om public void onSuccess(final Position result) { Coordinates coord = result.getCoordinates(); TransformGeometryRequest req = new TransformGeometryRequest(); GeometryFactory gf = new GeometryFactory(4326, 1); Point point = gf.createPoint(new Coordinate(coord.getLongitude(), coord.getLatitude())); req.setGeometry(GeometryConverter.toDto(point)); req.setSourceCrs("EPSG:4326"); req.setTargetCrs(mapWidget.getMapModel().getCrs()); GwtCommand command = new GwtCommand(TransformGeometryRequest.COMMAND); command.setCommandRequest(req); GwtCommandDispatcher.getInstance().execute(command, new CommandCallback<CommandResponse>() { @Override public void execute(CommandResponse response) { if (response.getErrors().isEmpty()) { org.geomajas.geometry.Geometry geom = ((TransformGeometryResponse) response) .getGeometry(); double accuracy = result.getCoordinates().getAccuracy(); Bbox box = new Bbox(geom.getCoordinates()[0].getX() - (accuracy / 2), geom.getCoordinates()[0].getY() - (accuracy / 2), accuracy, accuracy); mapWidget.getMapModel().getMapView().applyBounds(box, ZoomOption.LEVEL_FIT); } } }); } @Override public void onFailure(PositionError reason) { // TODO Auto-generated method stub } }); } event.stopPropagation(); }
From source file:org.geomajas.quickstart.gwt.client.ZoomToLocationController.java
License:Open Source License
public void onMouseUp(MouseUpEvent event) { // StyleElement se = (StyleElement) Document.get().getElementById("inlineStyle"); // se.setInnerText(".msRibbon { background: green; }"); final Geolocation geo = Geolocation.getIfSupported(); if (geo != null) { geo.getCurrentPosition(new Callback<Position, PositionError>() { @Override/*from w w w.j a v a2s . c om*/ public void onSuccess(final Position result) { Coordinates coord = result.getCoordinates(); TransformGeometryRequest req = new TransformGeometryRequest(); GeometryFactory gf = new GeometryFactory(4326, 1); Point point = gf.createPoint(new Coordinate(coord.getLongitude(), coord.getLatitude())); req.setGeometry(GeometryConverter.toDto(point)); req.setSourceCrs("EPSG:4326"); req.setTargetCrs(mapWidget.getMapModel().getCrs()); GwtCommand command = new GwtCommand(TransformGeometryRequest.COMMAND); command.setCommandRequest(req); GwtCommandDispatcher.getInstance().execute(command, new CommandCallback<CommandResponse>() { @Override public void execute(CommandResponse response) { if (response.getErrors().isEmpty()) { org.geomajas.geometry.Geometry geom = ((TransformGeometryResponse) response) .getGeometry(); double accuracy = result.getCoordinates().getAccuracy(); Bbox box = new Bbox(geom.getCoordinates()[0].getX() - (accuracy / 2), geom.getCoordinates()[0].getY() - (accuracy / 2), accuracy, accuracy); mapWidget.getMapModel().getMapView().applyBounds(box, ZoomOption.LEVEL_FIT); } } }); } @Override public void onFailure(PositionError reason) { // TODO Auto-generated method stub } }); } event.stopPropagation(); }
From source file:org.geomajas.quickstart.mobile.client.activity.MobileMapActivity.java
License:Open Source License
private void getGeoLocation() { final Geolocation geo = Geolocation.getIfSupported(); if (geo != null) { geo.getCurrentPosition(new Callback<Position, PositionError>() { @Override//from w w w . j a v a 2 s . c o m public void onSuccess(final Position result) { Position.Coordinates coord = result.getCoordinates(); TransformGeometryRequest req = new TransformGeometryRequest(); Geometry point = new Geometry(Geometry.POINT, 4326, -1); point.setCoordinates( new Coordinate[] { new Coordinate(coord.getLongitude(), coord.getLatitude()) }); GWT.log("Browser geolocation coords " + new Coordinate(coord.getLongitude(), coord.getLatitude())); req.setGeometry(point); req.setSourceCrs("EPSG:4326"); req.setTargetCrs(mapView.getMap().getMapPresenter().getViewPort().getCrs()); GwtCommand command = new GwtCommand(TransformGeometryRequest.COMMAND); command.setCommandRequest(req); GwtCommandDispatcher.getInstance().execute(command, new CommandCallback<CommandResponse>() { @Override public void execute(CommandResponse response) { if (response.getErrors().isEmpty()) { org.geomajas.geometry.Geometry geom = ((TransformGeometryResponse) response) .getGeometry(); GWT.log("Geomajas after transform coords " + geom.getCoordinates()[0]); /* double accuracy = result.getCoordinates().getAccuracy(); Bbox box = new Bbox(geom.getCoordinates()[0].getX() - (accuracy / 2), geom .getCoordinates()[0].getY() - (accuracy / 2), accuracy, accuracy); double res = mapView.getMap().getMapPresenter().getViewPort().getResolution(); double crr = mapView.getMap().getMapPresenter().getViewPort().getResolution(co + 3); mapView.getMap().getMapPresenter().getViewPort(). applyView(new View(geom.getCoordinates()[0], crr)); */ //Coordinate c = geom.getCoordinates()[0]; /* Coordinate c1 = new Coordinate(c.getX(), c.getY()); Coordinate c2 = new Coordinate(c.getX() + buffer, c.getY() + buffer); Geometry geometry = new Geometry(Geometry.LINE_STRING, 0, 0); geometry.setCoordinates(new Coordinate[] { c1, c2 });*/ //int co = mapView.getMap().getMapPresenter().getViewPort().getResolutionIndex(19); /* double minRes = mapView.getMap().getMapPresenter().getViewPort().getResolution(5); mapView.getMap().getMapPresenter().getViewPort(). applyView(new View(geom.getCoordinates()[0], minRes)); */ Bbox bbox = GeometryService.getBounds(geom); mapView.getMap().getMapPresenter().getViewPort().applyBounds(bbox); /* double resApply = mapView.getMap().getMapPresenter().getViewPort().getResolution(19); mapView.getMap().getMapPresenter().getViewPort().applyResolution(resApply);*/ /* mapView.getMap().getMapPresenter().getViewPort(). applyView(new View(geom.getCoordinates()[0], resApply));*/ } } }); } @Override public void onFailure(PositionError reason) { } }); } }
From source file:org.yocto.sample.client.WorldMap.java
License:Open Source License
public synchronized static void getLatLng(final AsyncCallback<LatLng> callback) { if (latLng == null) { Geolocation location = Geolocation.getIfSupported(); location.getCurrentPosition(new Callback<Position, PositionError>() { public void onFailure(PositionError reason) { callback.onFailure(reason); }//from ww w.ja v a2 s. c o m public void onSuccess(Position result) { logger.info("Location found at: " + result); latLng = LatLng.newInstance(result.getCoordinates().getLatitude(), result.getCoordinates().getLongitude()); callback.onSuccess(latLng); } }); } else { callback.onSuccess(latLng); } }