List of usage examples for com.google.gwt.maps.client.geocode Placemark getAddress
public final native String getAddress() ;
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"); }//from ww w . ja v a 2 s .c om 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);/* w w w.ja va 2 s . c om*/ 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:com.google.gwt.maps.sample.hellomaps.client.RoutedDirectionsDemo.java
License:Apache License
public RoutedDirectionsDemo() { final Grid grid = new Grid(1, 2); grid.setWidth("100%"); grid.getCellFormatter().setWidth(0, 0, "64%"); grid.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_TOP); grid.getCellFormatter().setWidth(0, 1, "34%"); grid.getCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP); map = new MapWidget(ATLANTA, 15); map.setHeight("480px"); map.addControl(new LargeMapControl()); grid.setWidget(0, 0, map);/*from ww w. jav a 2 s . com*/ DirectionsPanel directionsPanel = new DirectionsPanel(); grid.setWidget(0, 1, directionsPanel); directionsPanel.setSize("100%", "100%"); initWidget(grid); DirectionQueryOptions opts = new DirectionQueryOptions(map, directionsPanel); // Create directions from Midtown Atlanta to the Airport with a *few* // stops along the way. Directions.loadFromWaypoints(waypoints, opts, new DirectionsCallback() { public void onFailure(int statusCode) { Window.alert( "Failed to load directions: Status " + StatusCodes.getName(statusCode) + " " + statusCode); } public void onSuccess(DirectionResults result) { GWT.log("Successfully loaded directions.", null); // A little exercise of the route API List<Route> routes = result.getRoutes(); for (Route r : routes) { Placemark start = r.getStartGeocode(); GWT.log("start of route: " + start.getAddress(), null); Placemark end = r.getEndGeocode(); GWT.log("end of route: " + end.getAddress(), null); } } }); }