David Rauca
David Rauca

Reputation: 1583

Can I obtain the country name with Google Places API?

On the request for current place I receive a list of places. Every place has an address but that address is a string so I can't get only the country name.

Could someone help me on this matter?

Upvotes: 1

Views: 6211

Answers (2)

Scott
Scott

Reputation: 3732

Country is only explicitly available when using the Place Details API, not the Places API. (https://developers.google.com/maps/documentation/places/web-service/details)

You first need to look up a place_id for the specific place you're looking for. You then use your place_id to pull details from the Details API, which includes information like:

  • Fully formatted address, including country
  • Address components
  • Sample reviews
  • Phone # and website
  • Operating hours

Upvotes: 2

Hazarapet Tunanyan
Hazarapet Tunanyan

Reputation: 2865

If you have read the Google Places Autocomplete doc,you must know about API properties.you can use the type as '(region)' and will return you many results (plus country).And if you look inside address_components field (it's array with dynamic length),you will see,that the last item of array is what you need.Here is a great page to read a correct doc and try examples yourself.

http://www.w3docs.com/learn-javascript/places-autocomplete.html

Upvotes: 1

Related Questions