Example usage for com.google.gwt.maps.client.geocode Geocoder Geocoder

List of usage examples for com.google.gwt.maps.client.geocode Geocoder Geocoder

Introduction

In this page you can find the example usage for com.google.gwt.maps.client.geocode Geocoder Geocoder.

Prototype

public Geocoder() 

Source Link

Document

Creates a new instance of a geocoder that talks directly to Google servers.

Usage

From source file:com.apress.progwt.client.util.BulkGeoCoder.java

License:Apache License

public BulkGeoCoder(List<HasAddress> schools, String tablename) {
    this.schools = schools;
    this.tablename = tablename;
    geocoder = new Geocoder();
}

From source file:com.apress.progwt.client.util.BulkGeoCoder.java

License:Apache License

@Override
public void run() {

    final HasAddress school = schools.remove(0);
    if (school == null) {
        Log.debug("Finished");
        cancel();/*  w  w w  . j a va2  s . c  om*/
        return;
    }
    final String full = school.getFullAddress();
    Geocoder geocoder = new Geocoder();
    geocoder.getLatLng("1600 pennsylvania avenue, washington dc", new LatLngCallback() {
        public void onFailure() {
        }

        public void onSuccess(LatLng point) {
        }
    });

    geocoder.getLatLng(full, new LatLngCallback() {
        public void onFailure() {
            Log.debug("UPDATE " + tablename + " SET latitude = '-1',longitude  = '-1' WHERE id ="
                    + school.getId() + " LIMIT 1 ;");
            run();
        }

        public void onSuccess(LatLng point) {

            Log.debug("UPDATE " + tablename + " SET latitude = '" + point.getLatitude() + "',longitude  = '"
                    + point.getLongitude() + "' WHERE id =" + school.getId() + " LIMIT 1 ;");
            run();
        }
    });
}

From source file:com.google.gwt.maps.sample.hellomaps.client.Geocoder2Demo.java

License:Apache License

public Geocoder2Demo() {
    Panel panel = new FlowPanel();
    final FormPanel form = new FormPanel();
    form.setAction("#");
    Panel formElements = new FlowPanel();
    Label label = new Label("Search for an address:");
    formElements.add(label);/*from w w  w.ja v  a 2s  .  com*/
    final TextBox addressBox = new TextBox();
    addressBox.setVisibleLength(40);
    formElements.add(addressBox);
    Button submit = new Button("Search");
    submit.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            form.submit();
        }
    });
    formElements.add(submit);
    form.add(formElements);
    form.addFormHandler(new FormHandler() {
        public void onSubmit(FormSubmitEvent event) {
            showAddress(addressBox.getText());
            event.setCancelled(true);
        }

        public void onSubmitComplete(FormSubmitCompleteEvent event) {
        }
    });
    panel.add(form);

    map = new MapWidget(LatLng.newInstance(34, 0), 1);
    map.setSize("100%", "480px");
    panel.add(map);

    Grid grid = new Grid((sampleAddresses.length / NUM_ADDRESS_COLUMNS) + 1, NUM_ADDRESS_COLUMNS);

    for (int i = 0; i < sampleAddresses.length; i++) {
        final String address = sampleAddresses[i];
        Button link = new Button(address);
        // Hyperlink link = new Hyperlink(address, true,
        // "Extracting Structured Address Information");
        link.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                addressBox.setText(address);
                form.submit();
            }
        });
        grid.setWidget(i / NUM_ADDRESS_COLUMNS, i % NUM_ADDRESS_COLUMNS, link);
    }
    panel.add(grid);

    initWidget(panel);
    geocoder = new Geocoder();
}

From source file:com.google.gwt.maps.sample.hellomaps.client.GeocoderDemo.java

License:Apache License

public GeocoderDemo() {
    Panel panel = new FlowPanel();
    final FormPanel form = new FormPanel();
    form.setAction("#");

    Panel formElements = new FlowPanel();
    final TextBox address = new TextBox();
    address.setVisibleLength(60);//  ww w. java2  s  . c  om
    address.setText("10 10th Street, Atlanta, GA");
    formElements.add(address);
    formElements.add(buildLatLngPanel());
    this.displayLatLng(ATLANTA);

    Button submit = new Button("Go!");
    submit.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            form.submit();
        }
    });
    formElements.add(submit);
    form.add(formElements);
    form.addFormHandler(new FormHandler() {
        public void onSubmit(FormSubmitEvent event) {
            showAddress(address.getText());
            event.setCancelled(true);
        }

        public void onSubmitComplete(FormSubmitCompleteEvent event) {
        }
    });
    panel.add(form);

    map = new MapWidget(ATLANTA, 13);
    map.setSize("500px", "300px");
    panel.add(map);
    initWidget(panel);
    geocoder = new Geocoder();
}

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);/*from  ww w. j a  va 2  s . com*/
    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.livingstories.client.contentmanager.ContentItemManager.java

License:Apache License

/**
 * Creates event handlers for the Locations UI.
 *///  w  w w  .  j  a v  a2s.  c  om
private void createLocationHandlers() {
    // first, set up interactions between the widgets:
    final ClickHandler radioHandler = new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            adjustLocationControls();
            controlGeocodeButton();
        }
    };

    final KeyUpHandler textHandler = new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            controlGeocodeButton();
        }
    };

    useDisplayedLocation.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            radioHandler.onClick(event);
            locationDescriptionTextArea.setFocus(true);
        }
    });

    useAlternateLocation.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            radioHandler.onClick(event);
            alternateTextBox.setFocus(true);
        }
    });

    useManualLatLong.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            radioHandler.onClick(event);
            latitudeTextBox.setFocus(true);
        }
    });

    locationDescriptionTextArea.addKeyUpHandler(textHandler);

    alternateTextBox.addKeyUpHandler(textHandler);

    latitudeTextBox.addKeyUpHandler(textHandler);
    longitudeTextBox.addKeyUpHandler(textHandler);

    // Actually handle the geocode button:
    geocodeButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (useManualLatLong.getValue()) {
                // the latitude and longitude textboxes already have the right values in them
                recenterMap();
            } else {
                String address = (useDisplayedLocation.getValue() ? locationDescriptionTextArea
                        : alternateTextBox).getText();
                geocoderStatus.setText("");
                new Geocoder().getLatLng(address, new LatLngCallback() {
                    @Override
                    public void onFailure() {
                        geocoderStatus.setText("geocoding failed!");
                    }

                    @Override
                    public void onSuccess(LatLng point) {
                        geocoderStatus.setText("success");
                        latitudeTextBox.setText(String.valueOf(point.getLatitude()));
                        longitudeTextBox.setText(String.valueOf(point.getLongitude()));
                        recenterMap();
                    }
                });
            }
        }
    });

    map.addMapRightClickHandler(new MapRightClickHandler() {
        @Override
        public void onRightClick(MapRightClickEvent event) {
            LatLng clickedLatLng = map.convertContainerPixelToLatLng(event.getPoint());
            latitudeTextBox.setText(String.valueOf(clickedLatLng.getLatitude()));
            longitudeTextBox.setText(String.valueOf(clickedLatLng.getLongitude()));
            useManualLatLong.setValue(true);
            useManualLatLong.fireEvent(new ClickEvent() {
            });
            recenterMap();
        }
    });
}

From source file:com.google.livingstories.plugins.wordpress.livingstorypropertymanager.client.ui.LocationInput.java

License:Apache License

/**
 * Creates event handlers for the Locations UI.
 *//*from   w  w w  .j a  v  a 2s.  c o m*/
private void createLocationHandlers() {
    // first, set up interactions between the widgets:
    final ClickHandler radioHandler = new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            adjustLocationControls();
            controlGeocodeButton();
        }
    };

    final KeyUpHandler textHandler = new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            controlGeocodeButton();
        }
    };

    useDisplayedLocation.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            radioHandler.onClick(event);
            locationDescriptionTextArea.setFocus(true);
        }
    });

    useAlternateLocation.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            radioHandler.onClick(event);
            alternateTextBox.setFocus(true);
        }
    });

    useManualLatLong.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            radioHandler.onClick(event);
            latitudeTextBox.setFocus(true);
        }
    });

    locationDescriptionTextArea.addKeyUpHandler(textHandler);

    alternateTextBox.addKeyUpHandler(textHandler);

    latitudeTextBox.addKeyUpHandler(textHandler);
    longitudeTextBox.addKeyUpHandler(textHandler);

    // Actually handle the geocode button:
    geocodeButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (useManualLatLong.getValue()) {
                // the latitude and longitude textboxes already have the right values in them
                recenterMap();
            } else {
                String address = (useDisplayedLocation.getValue() ? locationDescriptionTextArea
                        : alternateTextBox).getText();
                geocoderStatus.setText("");
                new Geocoder().getLatLng(address, new LatLngCallback() {
                    @Override
                    public void onFailure() {
                        geocoderStatus.setText("geocoding failed!");
                    }

                    @Override
                    public void onSuccess(LatLng point) {
                        geocoderStatus.setText("success");
                        latitudeTextBox.setText(String.valueOf(point.getLatitude()));
                        longitudeTextBox.setText(String.valueOf(point.getLongitude()));
                        updateHiddenFieldValues();
                        recenterMap();
                    }
                });
            }
        }
    });

    map.addMapRightClickHandler(new MapRightClickHandler() {
        @Override
        public void onRightClick(MapRightClickEvent event) {
            LatLng clickedLatLng = map.convertContainerPixelToLatLng(event.getPoint());
            latitudeTextBox.setText(String.valueOf(clickedLatLng.getLatitude()));
            longitudeTextBox.setText(String.valueOf(clickedLatLng.getLongitude()));
            useManualLatLong.setValue(true);
            useManualLatLong.fireEvent(new ClickEvent() {
            });
            updateHiddenFieldValues();
            recenterMap();
        }
    });
}

From source file:com.ui.gwt.mobile.client.components.DetailPanel.java

License:Apache License

public void buildMap(Contact data) {
    if (mapWidget == null) {
        map.addClassName(AppResources.INSTANCE.css().map());
        mapWidget = new MapWidget();
        mapWidget.setWidth("100%");
        mapWidget.setHeight("400px");
        geocoder = new Geocoder();
        add(mapWidget);/*from   w  w  w.ja  v a 2 s . c  om*/
    }
    final InfoWindow info = mapWidget.getInfoWindow();
    final String address = data.getAddr1() + " " + data.getAddr2();
    geocoder.getLatLng(address, new LatLngCallback() {
        @Override
        public void onFailure() {
        }

        @Override
        public void onSuccess(LatLng point) {
            mapWidget.setCenter(point, 13);
            Marker marker = new Marker(point);
            mapWidget.clearOverlays();
            mapWidget.addOverlay(marker);
            info.open(marker, new InfoWindowContent(address));
        }
    });
}

From source file:org.onebusaway.webapp.gwt.common.control.GeocoderHelper.java

License:Apache License

public void query(String address) {
    Geocoder geocoder = new Geocoder();
    if (_view != null)
        geocoder.setViewport(_view);/*from   w  w  w .  j a va2 s . c  om*/
    geocoder.getLocations(address, new LocationHandler());
}

From source file:org.onebusaway.webapp.gwt.common.control.PlaceSearch.java

License:Apache License

public void query(String query, PlaceSearchListener listener, LatLngBounds view) {

    final LocationHandler handler = new LocationHandler(listener, view);

    // Google Local Search
    LocalSearch search = new LocalSearch();

    search.setAddressLookupMode(AddressLookupMode.ENABLED);
    if (view != null)
        search.setCenterPoint(view.getCenter());
    search.addSearchCompleteHandler(handler);
    search.execute(query);//  w  ww  .  ja va 2  s. c  om

    // Google Maps Geocoder Search
    Geocoder geocoder = new Geocoder();
    if (view != null)
        geocoder.setViewport(view);
    geocoder.getLocations(query, handler);

    handler.scheduleRepeating(1000);
}