Geocoding ambiguous addresses with google maps API

浪尽此生 提交于 2019-12-01 11:20:08

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/33505558/geocoding-ambiguous-addresses-with-google-maps-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!