Using the Google Map API to Display Customer Locations

21 Jun
June 21, 2012

Libraries make up one of the larger purchasing segments for our products, but demand is driven by the patrons of those libraries. So a challenge is how to reach out to those patrons, and increase demand.

One marketing suggestion was to give library patrons a way to see where libraries were that ‘carried’ our products. Fortunately, Google Maps provides a very easy to use solution for mapping groups of locations.

The first task for the proof of concept was to get a list of customer addresses. Our library e-commerce web site stores customer addresses, which we can cross check against online orders. I ran a query and got back the addresses (address1, address2, city, state, zip) for libraries that had made orders. I then transferred that data into a MySQL server that was on the box where the POC was going to run.

The second step was to geocode those addresses, which was the first stage where I was able to take advantage of the Google map api. allows you to pass an address as a parameter, and get back an xml file that includes tags for latitude and longitude. Looping through the database records and updating that data based on the xml was relatively trivial, with the caveat that Google limits how many requests you can make on the free interface. In a production application the initial coding might need to be done over multiple days, with updates running incrementally after that.

Finally, I needed to create a delivery platform for the map itself. I was using PHP for the proof of concept, so I created a php script that performed a distance based query on the address latitude and longitude data, with miles radius as a parameter.  With the returned records I was able to create an xml ‘file’ with a list of map nodes. A static html page in Apache provided a simple form (zip code and radius for my POC), and an embedded Google map. provides a javascript library for manipulating the embedded map. I looped through the map nodes to place them on the map, and there we go!

A couple of issues crop up in terms of how to use this tool. Do customers really want to show up on a map based search of ours, and which customer data do we use to seed the database? We’ll see how those questions play out. Whether this specific application ends up being implemented or not, I now know how simple it is to take advantage of the Google api for a variety of geospatial applications.

Jonathan Moody

Jonathan is an Application Developer at Findaway World, focusing on back end development for e-commerce web sites.

More Posts

© Copyright 2017 Findaway. All rights reserved.