{
feedback = new FeedbackPanel("feedback");
feedback.setOutputMarkupId(true);
add(feedback);
final GMap2 bottomMap = new GMap2("bottomPanel", new GMapHeaderContributor(
GMapExampleApplication.get().getGoogleMapsAPIkey()));
bottomMap.setOutputMarkupId(true);
bottomMap.setMapType(GMapType.G_SATELLITE_MAP);
bottomMap.addControl(GControl.GSmallMapControl);
add(bottomMap);
Form<Object> geocodeForm = new Form<Object>("geocoder");
add(geocodeForm);
final TextField<String> addressTextField = new TextField<String>("address",
new Model<String>(""));
geocodeForm.add(addressTextField);
Button button = new Button("client");
// Using GClientGeocoder the geocoding request
// is performed on the client using JavaScript
button.add(new GClientGeocoder("onclick", addressTextField, GMapExampleApplication.get()
.getGoogleMapsAPIkey())
{
private static final long serialVersionUID = 1L;
@Override
public void onGeoCode(AjaxRequestTarget target, int status, String address,
GLatLng latLng)
{
if (status == GeocoderException.G_GEO_SUCCESS)
{
bottomMap.getInfoWindow().open(latLng,
new GInfoWindowTab(address, new Label(address, address)));
}
else
{
error("Unable to geocode (" + status + ")");
target.addComponent(feedback);
}
};
});
geocodeForm.add(button);
// Using ServerGeocoder the geocoding request
// is performed on the server using Googles HTTP interface.
// http://www.google.com/apis/maps/documentation/services.html#Geocoding_Direct
geocodeForm.add(new AjaxButton("server", geocodeForm)
{
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
try
{
String address = addressTextField.getDefaultModelObjectAsString();
GLatLng latLng = GeoCodeGMapApplication.get().getServerGeocoder().findAddress(address);
bottomMap.getInfoWindow().open(latLng,
new GInfoWindowTab(address, new Label(address, address)));
}
catch (IOException e)
{
target.appendJavaScript("Unable to geocode (" + e.getMessage() + ")");