Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get only city name without country using google place API

I want only city name without country using google place API

For that I used react-places-autocomplete

I tried types: ['(cities)'] But it returns "Newyork, NY, USA" instead of "Newyork, NY"

I just want "Newyork, NY".

like image 901
Dhara Charola Avatar asked Oct 15 '25 13:10

Dhara Charola


2 Answers

It's not possible to remove country name from Place Autocomplete suggestions at this time.

However, there is an open feature request in Google's Issue Tracker which I suggest starring to increase visibility and subscribe to future updates: https://issuetracker.google.com/issues/35822039

Also check out this related thread for potential workarounds:
Google Places Autocomplete Remove State and Country from Result

Hope this helps!

like image 65
evan Avatar answered Oct 18 '25 23:10

evan


Feature Added on Sep 2022

For anyone looking to find a solution for like me, I found out that this feature has been added into the API as mentioned here

Good news! This feature is now available in the weekly channel.

To try this out, modify https://jsbin.com/qoxiwawuno/edit?html,js,output to set region=us (and add your API), then for instance typing "paris" will show

  • Paris, France
  • Paris, TX (no country name)

You can do so like this:

<script src="https://maps.googleapis.com/maps/api/jskey=API_KEY&callback=loadAutocomlete&libraries=places&region=fr&v=weekly" async ></script>
like image 32
Daniyal Nasir Avatar answered Oct 19 '25 01:10

Daniyal Nasir