Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store
Related Articles

Geocoding with PHP and the Google Maps API

Article Comments (13 total)

Displaying article comments 1 to 10 of 13
Kevin, 17 February 2010

Hi There, I would like a user to find a specific address then also have a list of all the suburbs within a 15km radius of that address? Has anybody got a clue or something similar? Much Appreciated...

g, 4 August 2009

cheers for the easy to use geocoder :)

drwe, 23 July 2009

Thanks for the article. You had mentioned something at the end about creating a caching solution. I have a table in my DB that containts the fields, (user_id, lat, lon) I want to be able to assign the returned latitude, and longitude with the highest accuracy to vaiables for easy database entry, I also want to be able to get the Address, city, state, and zip that is returned from the geocoder to maitain database consistancy. What syntax would I use and which class would I add it to to accomplish this task. I am not too familiar iwth OOP, so any help would be apreciated.

Christian Scholz, 30 June 2009

I uploaded all the files and tested test.php, but was stopped short by a fatal error message -- no cURL support on my server. I then edited Geocoder.php to make it use fopen() instead of curl functions and it seems to work.

I am uncertain, though, if the original and my version work exactly the same. Maybe someone can advise?

    // Geocoder.php 
    // I changed lines 32-35 ... 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $response = curl_exec($ch); 
    // ...into...
    $handle = fopen($url, "rb"); 
    $response = stream_get_contents($handle); 

Leandro, 27 March 2009
First tks for the tutorial!!! I'm in New Zealand and how can I set the country to get to Lat/Lon ? I tried put just street name and details but haven't got Lat/Lon cause the script can find an place for this address. Any suggestion ? By the away, I tried for: Adelaide street 23, Queenstown, Otago, new zealand

tropicCheese, 30 November 2008
hello ive managed to run the script on my vortual server but cam across a minor problem with the live server... it is not PHP5!! I would like to know more about downwards compatibilty mentioned earlier and could you be kind enought to highlight what needs changing in order for the script to work on php4

rafa, 28 November 2008
There's an error on index.php download file. It shows getLatitude on Longitude. It must be getLongitude.

John, 12 September 2008
First - thanks this article is excellent and very helpful... I did notice a small error in the index.php file that is downloadable... It calls getLat when it should be calling getLong: Longitude getPoint()-getLatitude()? Thanks so much for the great article. John

Anthony, 11 September 2008
I have got an error like this - Google Geo error 620 occurred , how to solve this problem and in which page it should be solved??? thank you

Andrew Parker, 9 June 2008
In the index.php file, change the reference to the Longitude coordinate to $placemark-getPoint()-getLongitude() . Currently it reads getLatitude() Thanks for the great work. I am new to coding and am trying to use your code to have an OpenLayers map zoom to the geocoded location. Any suggestions would be helpful. You can see my efforts at
Submit a Comment
Use the following form to submit a comment for this article. You can include any required code snippets, which we will format and highlight accordingly.

Note: Before your comment appears on PhpRiot, it must be manually approved. The email address field is optional. If you choose to include it, it will be displayed obfuscated to protect it from spammers.

In This Article

Additional Files