Im trying to write a function that will give return latitude and longitude from a zip code. I am attempting to use google maps api to do this.
I am seeing that geocoder seems to be good for this but I am struggling to know how to use it. What im looking to do is use a function to return a passed in zip code to return as an array with the latitude and longitude coordinates.
I created an account to get an API key. For example lets say my function is:
function getCoordinates (zipcode);
How can I write this out so that passed in zipcode would return the lat and long? Thanks for any responses!
You're right, geocoding api is what you need. Basically you have to perform a get request to
https://maps.googleapis.com/maps/api/geocode/json?address=YOUR_ZIP&key=YOUR_API_KEY
You also may want to specify a country for search. To achieve this, just add region
param with country code (for example region=us
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With