The predictions in place autocomplete might be a bit confusing. Let's have a look at the following example. I would like to find 'aeroport El Prat Barcelona'
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=aeroport%20El%20Prat%20Barcelona&key=YOUR_API_KEY
The first prediction has a text Aeroport, El Prat de Llobregat, Barcelona, Spain
with place Id ChIJO46GD4eepBIRIn5B25NbcNQ
. At first glance it seems to be airport, but when you check the types in the response you can see
"types":[
"transit_station","point_of_interest","establishment","geocode"
]
So this is not an airport, but the train station close to the airport as shown in the following screenshot.
At this point it looks like you cannot rely 100% on the type provided by autocomplete, because you can get something very close to the airport like the train or bus station that share the 'airport' in the name.
As a workaround I would suggest checking with places API nearby search if there is any airport close to coordinate returned by autocomplete. But this requires two additional steps:
Resolve place ID to coordinate. E.g. https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJO46GD4eepBIRIn5B25NbcNQ&key=YOUR_API_KEY
will return 41.3042622,2.0733891
Use nearby search to figure out if there is an airport in radius, for example 500 meters https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=41.3042622%2C2.0733891&radius=500&type=airport&key=YOUR_API_KEY
The last request returns the airport as shown in the following screenshot
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…