0

我试图让用户输入位置地址并在 gwt 中使用谷歌地图在地图上显示位置并将该位置用于其他服务。我正在使用 gwt-map 3.8。在线的 javadoc 对描述这个类的工作方式不是很有帮助,而且我在网上找不到任何示例。有人有什么想法吗?

这是我到目前为止所拥有的:

private void geocode()
{

    final String addr = addressBox.getText().toUpperCase().trim();
        addressBox.setFocus(true);

    addressBox.setText("");

    Geocoder G = Geocoder.create();
    GeocoderRequest GReq = GeocoderRequest.create();
    GReq.setAddress(addr);

        // should this be just create or createarray? it won't let me use createarray
    GeocoderResult GResult = GeocoderResult.create();


com.google.maps.gwt.client.Geocoder.Callback gcallback = new Geocoder.Callback() {      

        @Override
                // i don't understand this handle part, the first parameter is not 
                //defined in the javadoc.  I looked around online and it seems to be a 
                //array of geocoder result but I can't make the array because it's a 
                //javascript object
        public void handle(GeocoderResult a[], GeocoderStatus b) {

}}};

在此先感谢您的时间

4

1 回答 1

0

我相信您正在寻找的是:

String address = address1 + "," + number + "," + address2 + "," + city;
        GeocoderRequest request = GeocoderRequest.create();
        request.setAddress(address);
        Geocoder geoCoder = Geocoder.create();
        geoCoder.geocode(request, new Geocoder.Callback() {

            @Override
            public void handle(JsArray<GeocoderResult> a, GeocoderStatus b) {
                if (b == GeocoderStatus.OK) {
                    GeocoderResult result = a.shift();
                    map.setCenter(result.getGeometry().getLocation());
                } else {
                    Window.alert("Aconteceu algo errado no google ao pegar este local, confira endereco");
                }
            }      
            });
于 2013-01-01T12:32:04.160 回答