首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GWT: UiBinder + InputElement

GWT: UiBinder + InputElement
EN

Stack Overflow用户
提问于 2013-10-26 08:14:46
回答 1查看 831关注 0票数 1

我正在尝试在我的GWT应用程序中添加一个搜索栏,它利用了InputElement和AutoComplete。搜索栏基本上是在GoogleMap上搜索位置。下面是我到目前为止所做的代码:

代码语言:javascript
复制
@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>

我知道这不是完成这项工作的正确方法,因此我得到了以下错误:

com.google.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在com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)中未定义

请帮帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-28 03:22:57

我让它起作用了。守则的主要部分如下:

1)在.html文件中:(这是我之前错过的部分)

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

2)在我的java类中:(使用g:TextBox)

代码语言:javascript
复制
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);              
            }
        });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19604504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档