Shane Nelson
Shane Nelson

Reputation: 21

Google Place API city search by coordinates

I'm trying to access cities from the google place API. I want to be able to search with coordinates and have it return a city. My goal is for a user to be able to enter in a city and a photo shows up. So after getting the city, I will use the photo reference to get the image.

This is my request

https://maps.googleapis.com/maps/api/place/search/json?location=35.4107,80.8429&radius=100&sensor=true&key=API_KEY

the coordinates entered is a City in North Carolina. However, it does not return a city within North Carolina at all. All I am looking to do is use coordinates inside my request and have it return the city the coordinates are in. I'm relatively new to development, if I have been unclear in any way please point it out so that I may correct myself. Thanks!

Upvotes: 1

Views: 2273

Answers (1)

xomena
xomena

Reputation: 32178

I believe reverse geocoding is more suitable for your task than Places API. Places API is designed to search businesses and POIs at first place, localities shouldn't be among the results.

With reverse geocoding you can specify a coordinate and type of result you are looking for. For example, to search the city use the following request

https://maps.googleapis.com/maps/api/geocode/json?latlng=35.4107%2C-80.8429&result_type=locality&key=YOUR_API_KEY

This will return the "Huntersville, NC 28078, USA"

enter image description here

Upvotes: 2

Related Questions