-->

Geocoding ambiguous addresses with google maps API

2020-03-30 06:44发布

问题:

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