{ Getting Geocodes with PHP }

The Google Maps API has a “geocoder,” which is javascript, and which lets you get the geocodes for an address “on the fly.” Unfortunately, since this is time and resource intensive, if you have 60-something points you want to put on a map, the results are flaky at best. So you probably want to store the geocodes in the table with the address, right? You need a way to take the address from a form and get an address when the form is posted.

What you want to do is something like

$geocode = getGeocode("25 Monroe St Albany NY");

Attached are two files to help you do that. In “functions” you’ll find the getGeocode() function. You will need to change the URL being used. The other file is “getGeocode”, which actually goes out and gets the geocode. The only thing you have to change in this file is your Google Maps API key.

Be careful about what you get back. You would expect x,y, but Google likes to return y,x,z. You may have to do some manipulation.

For more info: read this.

functions.php

getgeocode.php

Leave a Reply

Your email address will not be published. Required fields are marked *