Sabbin
Sabbin

Reputation: 2445

Google Maps API - PlacesAutocomplete types issue

I'm currently working on an app with GoogleMaps API using their PlacesAutocomplete plugin to fill an input.

The problem which I encountered is that for the result types for Airports I get only establishment. I tried using establishment and geocode for parameters in the API call but with no luck. I either get only establishment or maximum transit_station in the results. The problem with transit_station is that all the train stations, airports, bus stations are marked the same.

I need a way to get the specific type for each of them, could someone help me please, maybe I'm doing something wrong.

You can see in the screenshot below the result from the API API Result with establishment set as type parameter in the call

Upvotes: 0

Views: 152

Answers (1)

Sabbin
Sabbin

Reputation: 2445

According to the documentation, currently the types parameter of places autocomplete supports only following values:

geocode
address
establishment
(regions)
(cities)

https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete

LE: Found a workaround

In order to get the place type I used another API this time Place Details

I took the placeId from the Autocomplete request and fired a new request to the Place Details with the fields parameter set to types

https://maps.googleapis.com/maps/api/place/details/json?key=[YOUR_KEY]&placeid=ChIJRQFUJVRhRUcR-C4yT1Y4KWk&fields=type

And the result was

{
    "html_attributions": [],
    "result": {
        "types": [
            "airport",
            "point_of_interest",
            "establishment"
        ]
    },
    "status": "OK"
}

So by combining the two calls I was able to get even the type which in the Autocomplete was not available

The docs for the the Place Details can be found here

Upvotes: 2

Related Questions