List of usage examples for com.google.gwt.maps.client.geocode LocationCallback LocationCallback
LocationCallback
From source file:com.google.gwt.maps.sample.hellomaps.client.Geocoder2Demo.java
License:Apache License
private void showAddress(final String address) { final InfoWindow info = map.getInfoWindow(); geocoder.getLocations(address, new LocationCallback() { public void onFailure(int statusCode) { Window.alert("Sorry, we were unable to geocode that address"); }//w w w. ja v a2s . c o m public void onSuccess(JsArray<Placemark> locations) { Placemark place = locations.get(0); Marker marker = new Marker(place.getPoint()); map.addOverlay(marker); String message = place.getAddress() + "<br>" + "<b>Country code:</b> " + place.getCountry(); info.open(marker, new InfoWindowContent(message)); } }); }
From source file:com.google.gwt.maps.sample.hellomaps.client.ReverseGeocoderDemo.java
License:Apache License
public ReverseGeocoderDemo() { VerticalPanel outer = new VerticalPanel(); map = new MapWidget(LatLng.newInstance(0, 0), 1); outer.add(map);//ww w.j a v a 2 s .c o m map.setSize("500px", "300px"); initWidget(outer); // Workaround for bug with click handler & setUItoDefaults() - see issue 260 MapUIOptions opts = map.getDefaultUI(); opts.setDoubleClick(false); map.setUI(opts); map.addMapClickHandler(new MapClickHandler() { public void onClick(final MapClickEvent event) { // Do not mis-interpret clicks on the info window and marker as // map click events to be reverse geocoded. if (event.getOverlay() != null) { return; } final Marker marker = new Marker(event.getLatLng()); final VerticalPanel panel = new VerticalPanel(); final InfoWindowContent content = new InfoWindowContent(panel); panel.add(new Label("LatLng: " + event.getLatLng().toString())); // Do a reverse geocode of this position geocoder.getLocations(event.getLatLng(), new LocationCallback() { public void onFailure(int statusCode) { Window.alert("Failed to geocode position " + event.getLatLng() + ". Status: " + statusCode + " " + StatusCodes.getName(statusCode)); } public void onSuccess(JsArray<Placemark> locations) { for (int i = 0; i < locations.length(); ++i) { Placemark location = locations.get(i); StringBuilder value = new StringBuilder(); if (location.getAddress() != null) { value.append(location.getAddress()); } else { if (location.getCity() != null) { value.append(location.getCity()); } if (location.getAdministrativeArea() != null) { value.append(location.getAdministrativeArea() + ", "); } if (location.getCountry() != null) { value.append(location.getCountry()); } } int ordinal = (i + 1); panel.add(new Label(" " + ordinal + ") " + value.toString())); } map.addOverlay(marker); map.getInfoWindow().open(marker, content); } }); marker.addMarkerClickHandler(new MarkerClickHandler() { public void onClick(MarkerClickEvent markerClickEvent) { if (!map.getInfoWindow().isVisible()) { map.getInfoWindow().open(marker, content); } } }); } }); geocoder = new Geocoder(); }
From source file:org.maps.client.Maps.java
License:Apache License
private void handleMapClick(final LatLng point) { LocationCallback callback = new LocationCallback() { public void onFailure(int statusCode) { // clicked somewhere off of the US }//from w ww. j a va 2s . c o m public void onSuccess(JsArray<Placemark> locations) { Placemark placemark = locations.get(0); handleMapClick(point, placemark, map.getZoomLevel()); } }; geocoder.getLocations(point, callback); }
From source file:org.maps.client.Maps.java
License:Apache License
private void performSearch(final String address) { if (address != null && !address.isEmpty()) { LocationCallback callback = new LocationCallback() { public void onFailure(int statusCode) { String message = "We could not find " + address + " due to: " + getMessage(statusCode); handleFailure(message);/*from www . j a v a 2 s .co m*/ } public void onSuccess(JsArray<Placemark> locations) { map.clearOverlays(); Placemark location = locations.get(0); map.setCenter(location.getPoint(), getZoom(location.getAccuracy())); refreshLayers(); } }; geocoder.getLocations(address, callback); } }