This jQuery plugin takes advantage of Google Maps API version 3 to create an easy to implement store locator. No back-end programming is required or used, you just need to feed it an XML file with all the location data. How you create the XML file is up to you. I originally created this for a company that didn’t have many locations, so I just used a static XML file. I also decided to geocode all the locations beforehand, to make sure it quick and to avoid any potential geocoding errors. However, if you’re familiar with JavaScript you could easily make a modification to geocode everything on the fly.
A note on the distance calculation: this plugin currently uses a distance function that was originally programmed by Chris Pietschmann. Google Maps API version 3 does include a distance calculation service (Google Distance Matrix API) but I decided not to use it because of the current request limits, which seem somewhat low. In addition, because the plugin currently calculates each location’s distance one by one, it appeared that I would have to re-structure some things to make all the distance calculations at once (or risk making many request for one location lookup). So, the distance calculation is “as the crow flies” instead of a road distance.
Forgot to remove one of the UTF-8 encoding lines in the Geocoder function.
Only a few special characters were working with the previous fix. Removed special encoding and all seem to be working now.
Replaced .serialize with .val on line 169 and added the line directly below, which encodes the string in UTF-8. This should solve special character issues with international addresses.
Added directions links to left column location list and HTML5 geolocation API option. Also did a little cleanup.
Added JSON compatibility, distance to location list, and an option for a default location. Also updated jQuery calls to the latest version (1.7.2) and removed an unnecessary line in the process form input function.
Serlialize was targeting any form on the page instead of the specific formID. Thanks to Scott for pointing it out.
Changed it so that the processing stops if the user input is blank.
Added a modal window option. Set slideMap to false and modalWindow to true to use it. Also started using the new jQuery .on() event api - make sure you're using jQuery v1.7+ or this won't work.
Left a couple of console.logs in my code, which was causing IE to hang.
This is my first jQuery plugin and the first time I’ve published anything on Github. Let me know if I can improve something or if I’m making some kind of mistake.