// 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);
}