When I search for an airport, I get results like this:
Clicking on that first result, "LaGuardia Airport (LGA)", however gives me this place result:
{
"address_components": [
{
"long_name": "New York",
"short_name": "New York",
"types": [
"locality",
"political"
]
},
{
"long_name": "East Elmhurst",
"short_name": "East Elmhurst",
"types": [
"neighborhood",
"political"
]
},
{
"long_name": "Queens",
"short_name": "Queens",
"types": [
"sublocality_level_1",
"sublocality",
"political"
]
},
{
"long_name": "Queens County",
"short_name": "Queens County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "New York",
"short_name": "NY",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
},
{
"long_name": "11371",
"short_name": "11371",
"types": [
"postal_code"
]
}
],
"formatted_address": "New York, Queens, NY 11371, USA",
"vicinity": "New York",
"html_attributions": []
}
"LaGuardia Airport" nor "LGA" are anywhere in the result.
How can I get the the name of the place?
Here's the gist of my code:
const autocomplete = new gmaps.places.Autocomplete(addressInput, {}); // {types: ['address']}
autocomplete.setFields(['address_component','formatted_address','vicinity']);
autocomplete.addListener('place_changed', () => {
let place = autocomplete.getPlace();
if (place.address_components && place.address_components.length) {
console.log(JSON.stringify(place, null, 2))
}
}