使用Google Maps API对不明确的地址进行地理编码 [英] Geocoding ambiguous addresses with google maps API

查看:74
本文介绍了使用Google Maps API对不明确的地址进行地理编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去(大约2015年1月),当我向Google Maps API发送地址片段时,我会取回与我的地址片段相匹配的内容的列表.例如,如果我输入"Crystal Street 16",我通常会获取可能的匹配项列表.现在,我得到的是部分匹配的单个结果.

有什么方法可以使Google Maps API返回与地址片段匹配的地址列表?

例如,在Java API中:

  public GeocodingResult [] queryService(){GeoApiContext context = new GeoApiContext().setApiKey(Geocoder.GOOGLE_API_KEY);GeocodingResult []结果;尝试{结果= GeocodingApi.geocode(上下文,"16 Crystal Street").await();返回结果;}捕获(异常e){e.printStackTrace();}返回null;} 

结果数组现在只包含一个项目,而它曾经包含多个与输入地址匹配的地址.

解决方案

地方自动填充更适合模棱两可或不完整的地址.特别是当这些内容来自用户键入时,请参见 JavaScript库.>

在使用这些方法中的任何一种时,请记住,视口偏移会大有帮助.使用JavaScript库时,将地图(如果有的话)绑定到自动完成"窗口小部件非常方便,这样,预测始终会受到地图视口的影响:

  autocomplete.bindTo('bounds',map); 

In the past (around January 2015 or so), when I sent an address fragment to the google maps API, I would get back a list of things that matched my address fragment. For example, if I put in "16 Crystal Street" I used to get a list of possible matches. Now, I get a single result that is a partial match.

Is there any way to make the google maps API return a list of addresses that match an address fragment?

In the java API, for example:

public GeocodingResult[] queryService()
{
    GeoApiContext context = new GeoApiContext().setApiKey(Geocoder.GOOGLE_API_KEY);
    GeocodingResult[] results;
    try
    {
        results = GeocodingApi.geocode(context,"16 Crystal Street").await();            
        return results;
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }               

    return null;
}

The results array now only has one item in it, whereas it used to contain multiple addresses that matched the input address.

解决方案

Places Autocomplete is a much better fit for ambiguous or incomplete addresses. Specially when these come from users typing, see the JavaScript library.

When using any of these, bear in mind that viewport biasing goes a long way. When using the JavaScript library, it's highly convenient to bind the map (if you have one) to the Autocomplete widget, so that predictions are influenced by the map's viewport all the time:

autocomplete.bindTo('bounds', map);

这篇关于使用Google Maps API对不明确的地址进行地理编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆