PhpRiot
Download This Article
Download this article in PDF format with all listings and files.

Price: $5.00 AUD
(Approx. $3.25 USD)

More information
Related Articles
Buy Me A Coffee

Your support keeps me writing — let me know if you want your name listed here also.
Related Books
Beginning Google Maps Applications with PHP and Ajax: From Novice to Professional

Beginning Google Maps Applications with PHP and Ajax: From Novice to Professional

There is much to like about this book. The explanations are straightforward, the code is...
Browse Articles
Ajax (4), APC (1), CAPTCHA (1), CSS (3), Debugging (1), File Upload (1), Google (3), Google Maps (2), JavaScript (12), JSON (2), MVC (1), MySQL (7), onbeforeunload (1), OOP (1), PHP (33), PhpDoc (1), PostgreSQL (6), Prototype (11), Reflection (1), RFC 1867 (1), Robots (1), Scriptaculous (1), SEO (1), Sessions (2), SimpleXML (1), Smarty (5), SOAP (2), SPL (1), Templates (2), W3C (1), XHTML (1), Zend Framework (6), Zend_Loader (1), Zend_Registry (1), Zend_Search_Lucene (1)

PhpRiot Newsletter
Your Email Address:

Geocoding with PHP and the Google Maps API

Introduction

Geocoding is the process of finding the longitude and latitude of a given address or location. The Google Maps service gives developers and web site owners free access to their geocoder, both using the Google Maps JavaScript API, as well as using the web service. In this article I will show you how to access the geocoder web service using PHP so that it can be used in your own applications.

There are many applications for a geocoder and having access to a free, reliable and frequently updated geocoder is a huge help in web application development. Some examples of where a geocoder can be useful include:

  • Plotting a user-submitted address on a map (such as a property owner listing their house on a real estate web site).
  • Discovering the longitude and latitude so calculations can be performed (such as a finding other sets of coordinates within a given distance).
  • Verifying addresses before shipping orders from your ecommerce store.
  • Retrieving the properly formatted address string for the given location. This is very useful when you consider how inconsistent users can be when entering their address.

When using Google Maps to display maps on your web site, it is easy to access the JavaScript based geocoder, however this isn't always an adequate solution, especially when it comes to accessibility.

For example, if your application saves coordinates based on a user-submitted address using the JavaScript geocoder, then this solution will not work for users who have JavaScript disabled. To overcome this we can use the web service instead, meaning all requests to the geocoder are performed on the server side.

In this article we will develop several PHP 5 classes that will make it easy to query the geocoder and access the response.

In This Article


Additional Files