bjorn2404 / jQuery-Store-Locator-Plugin

A store locator plugin using Google Maps API version 3
MIT License
493 stars 235 forks source link
google-maps javascript jquery jquery-plugin maps

jQuery Google Maps Store Locator Plugin

The files you're looking for are in the dist/ directory

Please see my blog for more information and examples.

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, you just need to feed it KML, XML, or JSON data with all the location information. How you create the data 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. You will need to geocode your locations beforehand or use a geocoding API service if you want to try to do it on the fly. The reason for this is that all free geocoding APIs have strict limits that would easily be exceeded. In the end, you're much better off storing the coordinates versus having to look them up for each location on each request.

A note on the distance calculation: this plugin currently uses a distance function that I found on the blog of 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. For v2 I also tried experimenting with the Directions API to request distances but also found the limits to be too restrictive. So, the distance calculation is “as the crow flies” instead of a road distance calculation. However, if you use the inline directions option that does provide the distance that's returned via the directions request.

Last, it’s very important to note that the plugin requires the Handlebars template engine. This separates the markup of the infowindows and location list elements so that they can easily be restructured. Handlebars pretty slick, will read Mustache templates, and the built-in helpers really come in handy. Depending on what your data source is, 2 of the 4 total templates will be used (KML vs XML or JSON) and there are options to set the paths of each template if you don’t want them in the default location. If you’re developing something for mobile devices the templates can be pre-compiled for even faster loading.

WordPress version

Cardinal Locator - WordPress store locator plugin is now available, which uses this jQuery plugin as a base and all of the settings can be set via a settings page in the WP dashboard. It also integrates with core WordPress features such as custom post types for location data and custom taxonomies for location categorization and filtering.

Changelog

Version 3.4.0

Version 3.3.0

Version 3.2.1

Version 3.2.0

Version 3.1.14

Version 3.1.13

Version 3.1.12

Version 3.1.11

Version 3.1.10

Version 3.1.9

Version 3.1.8

Version 3.1.7

Version 3.1.6

Version 3.1.5

Version 3.1.4

Version 3.1.3

Version 3.1.2

Version 3.1.1

Version 3.1.0

Version 3.0.1

Version 3.0.0

Version 3 has a breaking change with the dataLocation and dataType settings switching the default from XML to JSON.

Version 2.7.4

Version 2.7.3

Version 2.7.2

Version 2.7.1

Version 2.7.0

Version 2.6.2

Version 2.6.1

Version 2.6.0

Version 2.5.3

Version 2.5.2

Version 2.5.1

Version 2.5.0

Version 2.4.2

Version 2.4.1

Version 2.4.0

Version 2.3.3

Version 2.3.2

Version 2.3.1

Version 2.3.0

Version 2.2.2

Version 2.2.1

Version 2.2.0

Version 2.1.0

Includes contributions from from Giancarlo Gomez.

Version 2.0.9

Version 2.0.8

Version 2.0.7

Version 2.0.6

Version 2.0.5

Version 2.0.4

Version 2.0.3

Version 2.0.2

Version 2.0.1

Version 2.0.0

Version 2 is a complete rewrite of the plugin based on the "basic" plugin pattern of the jQuery Boilerplate. The overall file structure has changed, several of the plugin settings have changed and all of the CSS is now prefixed to avoid potential collisions. In other words, you're not going to be able to simply replace the main plugin file to upgrade to the latest version. I've been working on this update off and on for the past six months, so a lot has changed. I've also added many new features based on the most common requests I've received. The following list doesn't cover everything that's new but all of the important items to note:

Version 1.4.9

More contributions from Mathieu Boillat and Jimmy Rittenborg in addition to a few style updates:

Version 1.4.8

This update is made up of contributions from Mathieu Boillat and Jimmy Rittenborg:

Version 1.4.7

Added ability to feature locations so that they always show at the top of the location list. To use, set the featuredLocations option to true and add featured="true" to featured locations in your XML or JSON locations data.

Version 1.4.6

Fixed a bug where infowindows wouldn't open if the map div was changed.

Version 1.4.5

A minor update that includes the latest versions of jQuery and Handlebars, two new location variables and some clean-up.

Version 1.4.4

This update includes a bug fix for form re-submissions that was most apparent with the maximum distance example. It also includes a new jsonpCallback setting that was submitted by quayzar.

Version 1.4.3

A minor update with some clean up and additional language options.

Additions:

Fixes:

Version 1.4.2

This is another minor patch with a few important fixes and one addition. The plugin has also been submitted to the official jQuery plugin registry, which is finally back online.

Additions:

Fixes:

Note that if you try to use the minified version of jQuery 1.9.0 the plugin will error out in Internet Explorer due to the bug described in ticket 13315.

Version 1.4.1

This is a minor patch to switch array declarations to a faster method, fix line 682 to target with the loc-list setting instead of the div ID, and remove a duplicate locationset declaration on line 328.

Version 1.4

This is a large update that has many updates and improvements. It’s very important to note that the plugin now requires the Handlebars template engine. I made this change so that the data that’s displayed in the location list and the infowindows can be easily customized. I also wanted to separate the bulk of the layout additions from the main plugin file. Handlebars pretty slick, will read Mustache templates, and the built-in helpers can really come in handy. Depending on what your data source is, 2 of the 4 total templates will be used (KML vs XML or JSON) and there are options to set the paths of each template if you don’t want them in the default location. If you’re developing something for mobile devices the templates can be pre-compiled for even faster loading. Additionally, I’d also like to note that it probably makes more sense to use KML now as the data source over the other options but I’m definitely leaving XML and JSON support in. XML is still the default datatype but I may switch it to KML in the future.

New features:

Kilometers option
This was a no-brainer. You could make the change without too much trouble before but I thought I’d make it easier for the rest of the world.

Origin marker option
If you’d like to show the origin point, the originMarker option should be set to true. The default color is blue but you can also change that with the originpinColor option. I’m actually not positive how many colors Google has available but I know red, green and blue work - I would just try the color you want to see if it works.

KML support
Another obvious add-on. If you’d like to use this plugin with more customized data this would be the method I’d recommend because the templates are simplified to just name and description. So, you could put anything in the descriptions and not have to worry about line by line formatting. This method also allows you to create a map with Google “My Maps” and export the KML for use with this plugin.

Better JSONP support and 5 callbacks
Thanks to “Blackout” for passing these additions on. It should make working with JSONP easier and the callbacks should be helpful for anyone wanting to hook in add some more advanced customization.

ASP.net WebForms support
If you’re woking with ASP.net WebForms, including form tags is obviously going to cause some problems. If you’re in this situation simply set the new noForm option to true and make sure the formContainerDiv setting matches your template.

Maximum distance option
You can now easily add a distance dropdown with any options that you’d like. I’ve specifically added a new HTML file as an example.

Location limit now supports any number
This plugin was previously limited to only display a maximum of 26 locations at one time (based on the English alphabet). You can now set the limit to whatever you’d like and if there are more than 26 it will switch to just show dot markers with numbers in the location list.

Open with a full map of all locations
I had several requests asking how to accomplish this so I’ve added it as an option. There’s a new fullMapStart option that if set to true, will immediately display a map with all locations and the zoom will automatically fit all the markers and center.

Reciprocal focus
“JO” was particularly interested in adding this to the plugin and I finally got around to it. To accomplish reciprocal focus I add an ID to each marker and then add that same ID to each list element in the location list taking advantage of HTML5’s new data- attributes. I also added some jQuery to make the location list scroll to the correct position when its marker is clicked on the map.

Notes:

A few option names have changed, so be sure to take note of the changes before updating your files - especially people using JSON data.

I've included a basic LESS stylesheet without variables that can be used in place of the main map.css stylesheet. If you want to use it make any changes you want and compile it or include it in your main LESS file.

I’m somewhat concerned about the markers for future versions. Google has deprecated the Image Charts API, which is annoying (they always seem to deprecate the best things), but these should still continue to work for a long time. With that said though, my opinion of the look of Google’s markers is that they’re quite ugly. I was working on adding a new custom markers that could be controlled with CSS via the Rich Marker utility but I was unable to get that to work with the marker animations. I was also looking into using Nicolas Mollet’s custom marker icons, which look very nice compared to Google’s, but that project is apparently under maintenance until further notice. If you have suggestions on this concern I’d be interested in hearing them.

Version 1.3.3

Forgot to remove one of the UTF-8 encoding lines in the Geocoder function.

Version 1.3.2

Only a few special characters were working with the previous fix. Removed special encoding and all seem to be working now.

Version 1.3.1

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.

Version 1.3

Added directions links to left column location list and HTML5 geolocation API option. Also did a little cleanup.

Version 1.2

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.

Version 1.1.3

Serlialize was targeting any form on the page instead of the specific formID. Thanks to Scott for pointing it out.

Version 1.1.2

Changed it so that the processing stops if the user input is blank.

Version 1.1.1

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.

Version 1.0.1

Left a couple of console.logs in my code, which was causing IE to hang.

Version 1.0

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.