2
votes

I am trying to use Google Geocoding API and there does not seem to be a way to filter by multiple states. I can filter by one state (Ex. https://maps.googleapis.com/maps/api/geocode/json?address=Elm+St&components=administrative_area:WA|country:US&key=API_KEY)

Does anyone know how to filter by multiple states?

1
What results are you trying to achieve? Are you wanting a list of all the states that have Elm St in them? - SunSparc
I've done a bit more digging since this post and from what I can tell it doesn't look like what I want to achieve is possible. So in short, list only the Elm Streets in WA, ID, and OR like so (or other methods to achieve the same results). components=administrative_area:WA,ID,OR - JeremyT

1 Answers

0
votes

I do not know how to achieve this with the Google API, but I do know how to do it with the SmartyStreets Autocomplete API.

A simple GET request with the state_filter option will do what you want. Here is an example:

curl "https://autocomplete-api.smartystreets.com/suggest?prefix=Elm+St&state_filter=wa,id,or&auth-id=<your-auth-id>"

Broken out we see these parameters:

hostname: autocomplete-api.smartystreets.com
prefix: Elm St
state_filter: WA,ID,OR
auth-id: <a-valid-smartystreets-auth-id>

The prefix should be part of an address that you are looking for. The Autocomplete API is used for suggesting addresses as users type an address into an address field in a web form. But you can access it directly to achieve your stated purpose.

The results of this request would be a JSON string:

{
    "suggestions": [
        {
            "text": "Elm St, Bellevue ID",
            "street_line": "Elm St",
            "city": "Bellevue",
            "state": "ID"
        },
        {
            "text": "W Elm St, Almira WA",
            "street_line": "W Elm St",
            "city": "Almira",
            "state": "WA"
        },
        {
            "text": "Elm St SW, Albany OR",
            "street_line": "Elm St SW",
            "city": "Albany",
            "state": "OR"
        },
        // 7 other results were truncated
    ]
}

Note: To use any of the SmartyStreets APIs, you need a valid auth-id, which you can get easily when you signup for a free account.

(Disclaimer: I work for SmartyStreets)