Example usage for com.google.gwt.maps.client.placeslib Autocomplete getPlace

List of usage examples for com.google.gwt.maps.client.placeslib Autocomplete getPlace

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.placeslib Autocomplete getPlace.

Prototype

public final native PlaceResult getPlace() ;

Source Link

Document

Returns the details of the Place selected by the user, or null if no Place has been selected yet.

Usage

From source file:com.google.gwt.maps.testing.client.maps.AutocompletePlacesMapWidget.java

License:Apache License

private void drawAutoComplete() {

    Element element = tbPlaces.getElement();

    AutocompleteType[] types = new AutocompleteType[2];
    types[0] = AutocompleteType.ESTABLISHMENT;
    types[1] = AutocompleteType.GEOCODE;

    AutocompleteOptions options = AutocompleteOptions.newInstance();
    options.setTypes(types);/*  ww  w .jav a 2s  . co  m*/
    options.setBounds(mapWidget.getBounds());

    final Autocomplete autoComplete = Autocomplete.newInstance(element, options);

    autoComplete.addPlaceChangeHandler(new PlaceChangeMapHandler() {
        public void onEvent(PlaceChangeMapEvent event) {

            PlaceResult result = autoComplete.getPlace();

            PlaceGeometry geomtry = result.getGeometry();
            LatLng center = geomtry.getLocation();

            mapWidget.panTo(center);
            // mapWidget.setZoom(8);

            GWT.log("place changed center=" + center);
        }
    });

    mapWidget.addBoundsChangeHandler(new BoundsChangeMapHandler() {
        public void onEvent(BoundsChangeMapEvent event) {
            LatLngBounds bounds = mapWidget.getBounds();
            autoComplete.setBounds(bounds);
        }
    });
}

From source file:pl.itrack.client.local.services.maps.ClassicMapService.java

License:Apache License

private Autocomplete createAutoCompleteWithChangeListener(TextBox searchBox) {
    Element element = searchBox.getElement();
    final Autocomplete autoComplete = Autocomplete.newInstance(element, getAutoCompleteOptions());

    autoComplete.addPlaceChangeHandler(event -> {

        PlaceResult result = autoComplete.getPlace();

        PlaceGeometry geometry = result.getGeometry();
        LatLng center = geometry.getLocation();

        getMapWidget().panTo(center);/* w  w  w . j  a  va  2 s.c o  m*/
        getMapWidget().setZoom(ZOOM);
    });
    return autoComplete;
}