2013-10-26 7 views
1

InputElement와 AutoComplete를 이용하는 GWT 웹 앱에 검색 막대를 추가하려고합니다. 검색 창은 기본적으로 Google지도에서 위치를 검색하는 것입니다.GWT : UiBinder + InputElement

com.google :이 다음과 같은 오류가 작업을 할 따라서 내가 얻고 올바른 방법으로하지 않은 것을 알고

@UiField 
InputElement input; 
// 
// 
// 
final Autocomplete autocomplete = Autocomplete.create(input);  
     final InfoWindow infowindow= InfoWindow.create(); 
     autocomplete.addPlaceChangedListener(new PlaceChangedHandler(){ 
      public void handle(){ 
       PlaceResult place=autocomplete.getPlace(); 
       String address=place.getAddressComponents().get(0).getShortName(); 
       infowindow.setContent(place.getName()+", "+address);    
       addMarker(place.getGeometry().getLocation(),place,infowindow); 
       map.setCenter(place.getGeometry().getLocation()); 
       map.setZoom(17.0);  

      } 
     }); 
// 
// 
// 
<g:north size='5'> 
      <g:HTMLPanel> 
       <div> 
        <g:Label ui:field="label1">PublicFortress</g:Label> 
       </div> 
       <div> 
        <g:Anchor ui:field="signin" href="#">SignIn</g:Anchor> 
        <g:Button ui:field="home">Home</g:Button> 
        <div> 
         <input type="text" name="Search" ui:field="input" class="custom" /> 
        </div> 

       </div>   

      </g:HTMLPanel> 
     </g:north> 

: 여기에 내가 지금까지 만든 코드입니다 .gwt.core.client.JavaScriptException : (TypeError) @ com.google.maps.gwt.client.places.Autocomplete :: create (Lcom/google/gwt/dom/client/InputElement) ([JavaScript object 30)]) : $ wnd.google.maps.places가 정의되지 않았습니다. at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript (BrowserChannelServer.java:249)

도와주세요!

+0

대신 을 사용하지 않으시겠습니까? – chkal

+0

g : TextBox를 사용해 보았는데 동일한 오류가 발생했습니다. 제가 한 주요 변화가 있었다 : 1) \t 2) 텍스트 상자 입력 @UiField 검색; 3) 최종 자동 완성 autocomplete = Autocomple.newInstance (input.getElement(), null); – Dexter

+0

죄송합니다. 오류가 동일하지 않습니다. com.google.gwt.core.client.JavaScriptException :(TypeError) @ com.google.gwt.maps.client.placeslib.Autocomplete :: createJso (Lcom/google/gwt/dom)/client/Element; Lcom/google/gwt/maps/client/placeslib/AutocompleteOptions;) ([JavaScript object (36), null]) : $ wnd.google.maps.places가 정의되지 않았습니다. – Dexter

답변

0

나는 그것을 작동시켰다.

1) .html 파일에서 : : 코드의 주요 부품 (이건 내 자바 클래스에서 앞서를 놓쳤던 부분)

<head> 
. 
. 
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script> 
</head> 

2)입니다 : (사용 g : 텍스트 상자)

final AutocompleteOptions options = AutocompleteOptions.newInstance(); 
     final Autocomplete autocomplete = Autocomplete.newInstance(input.getElement(), options);  
     final InfoWindow infowindow= InfoWindow.create(); 
     autocomplete.addPlaceChangeHandler(new PlaceChangeMapHandler(){ 

      @Override 
      public void onEvent(PlaceChangeMapEvent event) { 
       PlaceResult place=autocomplete.getPlace(); 
       String address=place.getAddress_Components().get(0).getShort_Name(); 
       infowindow.setContent(place.getName()+", "+address);   
       LatLng latLng = LatLng.create(place.getGeometry().getLocation().getLatitude(), place.getGeometry().getLocation().getLongitude()); 
       addMarker(latLng,place,infowindow); 
       map.setCenter(latLng); 
       map.setZoom(17.0);    
      } 
     });