public static void searchForAddress(String address) {

    switchToMapView();

    Geocoder geocoder = new Geocoder();
    geocoder.setViewport(getSearchBoundsAsLatLngBounds(20 * 1000));
    geocoder.getLocations(address, new AddressHandler());
  }
Beispiel #2
0
  /** Run the query and load the map */
  public void runQuery() {
    String query = queryTextBox.getValue();
    if (isValidQuery(query)) {
      LatLng latlng = parseLatLng(query);
      if (latlng == null) {
        queryTextBox.setValue("");
      } else {
        Geocoder geocoder = new Geocoder();
        latlng = parseLatLng(latlng.toUrlValue(6));
        if (latlng != null) initMap(map.getElement(), latlng);
        else initMap(map.getElement(), LatLng.newInstance(0.0, 0.0));
        geocoder.getLocations(
            query,
            new LocationCallback() {
              @Override
              public void onFailure(int statusCode) {
                // Window.alert("failed");
                Document.get().getElementById("responseCount").getStyle().setDisplay(Display.NONE);
                Document.get().getElementById("matches").getStyle().setDisplay(Display.NONE);
              }

              @Override
              public void onSuccess(JsArray<Placemark> locations) {
                responseGeocode(locations, true);
              }
            });
      }
    } else {
      initMap(map.getElement(), LatLng.newInstance(0.0, 0.0));
      Geocoder geocoder = new Geocoder();
      // map.setUIToDefault();
      geocoder.getLocations(
          query,
          new LocationCallback() {
            @Override
            public void onFailure(int statusCode) {
              // Window.alert("failed");
              Document.get().getElementById("responseCount").getStyle().setDisplay(Display.NONE);
              Document.get().getElementById("matches").getStyle().setDisplay(Display.NONE);
            }

            @Override
            public void onSuccess(JsArray<Placemark> locations) {
              responseGeocode(locations, false);
            }
          });
    }
  }
  /**
   * Called when search button is clicked and search query is not empty
   *
   * @param text
   */
  public void onSearch(String text) {
    Geocoder g = new Geocoder();
    g.getLocations(
        text,
        new LocationCallback() {

          @Override
          public void onSuccess(JsArray<Placemark> locations) {
            if (locations.length() > 0) {
              Placemark marks = locations.get(0);
              onSearchAddressResult(marks);
            }
          }

          @Override
          public void onFailure(int statusCode) {}
        });
  }
Beispiel #4
0
  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");
          }

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