Hello. I am trying to use Google’s reverse geocoding to take coordinates (long and lat) and return addresses. I just copy pasted their reverse geocoding code but don’t know what to do next to get the address to print itself out into a div. I would greatly appreciate any help. The code is in codepen and I would greatly appreciate feedback.
Getting an accurate city, region, and country took me close to a day to figure out. You need to study the JSON that gets returned from the google maps API and try it with various Latitude + Longitude values to see how it works. Once you get it working for your own location, you’ll notice that it may not work in other locations…so it takes some work to get it right.
Once I got my code working, I found this codepen and it helped me make some adjustments:
After that, I got more feedback from other campers, and made even more adjustments…
To be honest, you might want to try an easier approach for now and use the weather API that Free Code Camp recommends - that weather API gives you the city name in the JSON it returns. https://fcc-weather-api.glitch.me/
You could also use a IP-location API to get the city, like the one at: https://ipinfo.io/json (just keep in mind that ip addresses are not 100% accurate indicators of a user’s location)