Geocoding with PHP and the Google Maps API
Conclusion
In this article we have looked closely at how to use the free geocoder web service provided to users of Google Maps. While there is also a geocoder than can be used within your JavaScript code when using the Google Maps API, not all users will necessarily have JavaScript. This means that if you do choose to use the JavaScript geocoder, you should not rely on the user being able to do so.
After learning how to perform a request and to understand the results, we implement a PHP solution made up of three classes: Geocoder, Placemark and Point, which make using the Google geocoder very straightforward.
We finished the article by implementing a simple web-based interface to the geocoder, which allowed users to enter an address and retrieve the resulting locations.
While we didn't implement a caching solution in this article, you should always try to minimize the number of geocoding requests that your application performs by saving the responses for future use. This is done not only increase performance but to also not go over the quota allocated by Google.
References
- Google Maps Geocoder Documentation: http://code.google.com/apis/maps/documentation/services.html#Geocoding
- Google Maps API Reference: http://code.google.com/apis/maps/documentation/reference.html
Other Options
- Download a PDF version of this article
- Put your PHP knowledge to the test with our online and iPad/iPhone quizzes
- View or post comments for this article
- Browse similar articles by tag: Google, Google Maps, PHP, SimpleXML
- Read related article:




