Building the map
At a very high level building the "BTech96 Across the World" map requires:- Google Maps API (obviously, to generate the map)
- Simple AJAX coding (for refreshing the search results without reloading the page)
- PHP (the engine for the server-side stuff)
- MySQL (to store the information)
<script src="http://maps.google.com/maps?file=api&v=2&key=whatever_your_key_is"
type="text/javascript"></script>
The above ensures that the javascript content defined in the Google Maps API is accessible by the page.
Going into the details, here is what I did:
- Wrote a program to get the coordinates (i.e. latitude and longitude) of any place. Note that if you already have the coordinates for each place then you don't need this part. I made use of the GeoCode functionality provided in the Google APIs to retrieve the coordinates. I need the coordinates to place a marker on the map.
- I first tried the standard JavaScript based approach, but ran into issues where the GeoCode was returned before being fully generated (timeout issues because the call is asynchronous).
- I then used a PHP-based variant.
- The GeoCoder returns a CSV file.
- I ran into problems with processing the CSV because my ISP has some security concerns regarding reading a file through HTTP in PHP (
file_get_contents). Instead I had to use CURL.
- Created a locations table in MySQL with fields for Entry Number, address and coordinates. Note that a person can have multiple locations
- Built the map based on the locations
- Iterated through the table
- For each location:
- Grouped all the people in that location
- Created a marker by invoking the
GMarkerclass on the coordinates of each location - Displayed the marker on the map.
- Added an
"onclick"for each marker, to show the popup with the names of the people on the batch.
- Built the Search using AJAX
- The search string is passed to a different PHP using the
XMLHttpRequestobject (in Firefox, Opera and Safari) or theXMLHTTPobject (in IE) - The search runs a very simple query - it checks for matches in the name, entry number and nicknames.
- For every match the search tries to determine if there is a location. The results are grouped based on the availability of the location information for a given person.
- The matches are linked to the corresponding markers on the map based on the coordinates of the location.
- The results are passed to XMLHttpRequest / XMLHTTP object, which updates the search result without reloading the page.
- The search string is passed to a different PHP using the