GWT Maps V3 Api中的SearchBox(branflake2267 / GWT-Maps-V3-Api版本3.8.1)

时间:2015-05-25 10:40:04

标签: javascript google-maps gwt google-maps-api-3

我正在使用GWT Maps Api V3开发应用程序。我尝试创建地方搜索框,例如Google Maps JavaScript API(链接Place search box - Google Maps JavaScript API

的示例

我查看了javascript代码,他们使用google.maps.places.SearchBox创建了SeachBox但是在GWT Maps Api V3(版本3.8.1,GWT-Maps-V3-Api)中,没有类名SearchBox。我想我可以使用autocomplete和html输入字段创建一个SearchBox。但我无法将我的输入字段放在我的地图中。所以,我的问题是:使用GWT Maps V3 Api创建SearchBox的正确方法是什么? 感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我通过使用方法解决了我的问题(在branflake2267 / GWT-Maps-V3-Api版本3.8.1上)

  

void com.google.gwt.maps.client.MapWidget.setControls(ControlPosition controlPosition,Widget widget)

首先,我创建一个文本框

private TextBox placeSearchTextField = new TextBox();

并使用setControls:

mapWidget.setControls(ControlPosition.TOP_LEFT, placeSearchTextField );

添加自动填充

private void drawAutoComplete() {

    Element element = placeSearchTextField.getElement();

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

    AutocompleteOptions options = AutocompleteOptions.newInstance();
    options.setTypes(types);

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

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

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

有一些CSS,我得到了结果 enter image description here

相关问题