List of usage examples for com.google.gwt.geolocation.client Geolocation getCurrentPosition
public native void getCurrentPosition(Callback<Position, PositionError> callback, PositionOptions options) ;
From source file:it.bz.tis.sasabus.html5.shared.ui.map.SASAbusMapAttachHandler.java
License:Open Source License
@Override public void onAttachOrDetach(AttachEvent event) { if (event.isAttached()) { this.map.leafletMap = new Map(this.map.mapDiv.getElement()); this.map.leafletMap.addLayer(new OSMLayer()); this.map.fitAllAreas(); this.map.refreshBaseLayerAfterZoomLevelAndPosition(); this.map.leafletMap.addZoomEndEventListener(new EventListener() { @Override/*www . j a va2s. c o m*/ public void onEvent() { SASAbusMapAttachHandler.this.map.refreshBaseLayerAfterZoomLevelAndPosition(); } }); this.map.leafletMap.addDragEndEventListener(new EventListener() { @Override public void onEvent() { SASAbusMapAttachHandler.this.map.refreshBaseLayerAfterZoomLevelAndPosition(); } }); this.map.gpsIcon.addClickHandler(new DMClickHandler() { @Override public void onClick(DMClickEvent event) { PositionOptions positionOptions = new PositionOptions(); positionOptions.setHighAccuracyEnabled(true); positionOptions.setTimeout(10000); // http://openlayers.org/dev/examples/geolocation.html Geolocation geoloc = Geolocation.getIfSupported(); if (geoloc != null) { geoloc.getCurrentPosition(new Callback<Position, PositionError>() { @Override public void onSuccess(Position result) { double lon = result.getCoordinates().getLongitude(); double lat = result.getCoordinates().getLatitude(); double accuracy = result.getCoordinates().getAccuracy(); Window.alert("lat: " + lat + " lon: " + lon + " acc (meter): " + accuracy); LatLng position = new LatLng(lat, lon); SASAbusMapAttachHandler.this.map.leafletMap.setView(position, 16); } @Override public void onFailure(PositionError reason) { Window.alert("Failure: " + reason.getMessage()); } }, positionOptions); } else { Window.alert("Your browser does not support localization"); } } }); } }