jQuery Store Locator Plugin
I can’t believe it’s been over a year since I first published my Google Maps store locator JavaScript code. I’ve had several requests for an updated version and that post has definitely received more traffic than any of my others. I’ve finally created a new version of the locator using Google Maps API version 3 and this time I’ve turned it into a full-on jQuery plugin. I re-worked almost everything in the code but I don’t think I’m going to go through function by function like I did in the last post. jQuery should make this store locator much easier to implement and I’ve included several options. Without further ado, here is the full documentation for the plugin:
jQuery Google Maps Store Locator Plugin
Files can be downloaded from GitHub and will be in the /dist directory
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.
Options
It is much easier to maintain the current list of options on GitHub vs. a gigantic HTML table, which is why I’m now including the options.md file in the repository. If you need to view options for a previous version please view the old options page.
Usage:
Assuming you already have your locations.xml file set up in the current directory and the basic HTML copied from the example index file, the following would be the simplest usage example:
1. Include the css file (you’ll most likely want to make modifications to this beforehand):
<link rel="stylesheet" type="text/css" href="assets/css/storelocator.css">
2. Include jQuery if you don’t have it on your page already (the example below uses the Media Temple CDN but you can load it from wherever you’d like):
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
3. Include the latest version of Handlebars.js (this is now required)
<script src="assets/js/libs/handlebars.min.js"></script>
4. Create a new Google Maps API key and make sure to enable Google Places API Web Service, Google Maps Geocoding API and Google Maps Directions API for the project in the Google API Console after setting up the initial Maps key.
5. Include Google Maps API with your key. If you want to target a particular country add “®ion=” to the end of the URL followed by the country code.
<script src="https://maps.google.com/maps/api/js?key=yourkey"></script>
Region targeting example:
<script src="https://maps.google.com/maps/api/js?key=yourkey®ion=UK"></script>
6. Include the plugin file:
<script src="assets/js/plugins/storeLocator/jquery.storelocator.js"></script>
7. Apply the storeLocator plugin to the map-container div.
<script> $(function() { $('#bh-sl-map-container').storeLocator(); }); </script>
8. Make sure you have the basic form and map container HTML set up or copied from the example file.
Geocoding:
To geocode all your locations you can use a free or paid service or use the geocode.html that I included. This provides a basic form and will use the Google Maps API to give you the latitude and longitude of the location you input.
JSON (optional):
I’ve added JSON support as an option with version 1.2 of the plugin, which is completely optional. The JSON file included in the GitHub repository is just there as an example. The file was generated via PHP from a MySQL database. The database structure I used for the example is pictured in the following image:
Outputting the JSON from the database is extremely simple with PHP. Make the database connection with MySQLi and use something such as:
$results = $db->query("SELECT * FROM locations"); $locations = array(); foreach($results as $location){ array_push($locations, $location); } //Output JSON echo json_encode($locations);
Then you’d just set the dataLocation setting in the plugin directly to the PHP file and the dataType setting to json.
Support:
I’ll try to answer basic questions and create more examples but my time is limited.
- Demo example
- Modal window example
- Default location example
- HTML5 auto geocode example
- KML example
- JSON example
- Maximum distance example
- No form tags example
- Bootstrap (responsive) example
- Category filtering example
- Custom category markers example
- Inline directions example
- Name search example
- Pagination example
- Raw data example
- Query string example
- XML format example for location data
Tutorials
- Using the jQuery Store Locator with thousands of locations
- Using query string parameters with the jQuery Store Locator
Cardinal Store Locator
Donations
Some people have asked to donate. Feel no obligation but if you want to my Paypal email is bjorn2404@gmail.com and I also have a Bitcoin address set up: 17ueYyfaxCyEXedecVnr3w7GjM9PJD4CHj
Special thanks
My initial motivation for creating this jQuery plugin was a custom implementation request of my older JavaScript locator for Phin & Phebes Ice Cream. If you’re on the east coast be sure to seek out a pint.
Oops! We could not locate your form.
Hi Bjorn,
This is a fantastic plugin you’ve developed. I’d like to know is it possible to have 2 dropdowns for user to click instead of typing in a search box to search? For example, 1 dropdown for State, another 1 for City. The City is dependent on State. When a user chose a State and the City, click search button, the map will returned results for all stores in that State and City regardless of distance.
May I know is this possible and is it a major customization?
I’m very close to finishing a new version of the plugin that has built-in filtering support. I’m hoping to have it all finalized within the next couple of weeks.
Exciting! Any pre-release version available by chance?
You can check out the development branch on Github. It’s completely restructured, none of the new stuff is documented yet, and I’m still committing updates on a semi-regular basis.
Hi Bjorn – thank you for the plugin – it’s awesome! I’m currently working on a corporate solution to a national location finder and I’m hoping you have an idea of how to move the infowindow contents. I’d like them to be in a sliding div that comes up over the map about 3/4s of the way so the top view is map but there is a div with all of the information below it. Ideas?
Hi,
I’m getting this error:
Uncaught Error: Parse error on line 13:
…th}}Directions{{/…” /> <meta…
———————–^
Expecting 'ID', got 'STRING'
In my local server it works, but on the live server I get the error.
The only difference is that in the site's server I'm loading the json file with a full URL, so I guess that's where the error is coming from.
I'm using the sample json file:
it's here: http://cdn.shopify.com/s/files/1/0164/8952/t/1/assets/locations.json
And this is the code:
$(function() {
$('#map-container').storeLocator({'slideMap' : true, 'modalWindow': false, 'zoomLevel': 4, 'distanceAlert': -1, 'defaultLoc': true, 'defaultLat': '39.808465', 'defaultLng' : '-98.555382', 'dataType': 'json', 'dataLocation': 'http://cdn.shopify.com/s/files/1/0164/8952/t/1/assets/locations.json'});
});
What am I doing wrong?
I forgot to add that the error is at Line 305 of the handlebars file
my xml looks like
“”
I only use name lat lng address and sometimes web.
on my web page after i’ve entered a postal code it shows me my store on the left side like this
“LOWELL
5364 St Laurent, Montreal QC
,
3.8 kilometers
Directions”
ALL of my stores shows a comma “,” between the address and the distance .. does someone know where’s that come from .. there’s no comma in my xml
That is from the template that displays the data. Simply wrap the elements in an IF block and it won’t display the blank lines with the commas. If you do not want them at all, just delete them from the template file.
Thanks a lot for this plugin, it’s a really great job.
For my client, I need to use a fixed map. I modified your code for it and maybe it would be interesting to add this possibility to the plugin with an option “staticmap:true” ?
Hello, I have a dynamic zoomLevel to do. How can I do that ? Thanks !
Hi there… . is there a way to get the individuals GeoCoded location (ZIP code specifically) to be automatically populated into the ZIP code field?
Great code. Very nice work.
Russ
I wish if I would find this earlier. Its a great script indeed, I have a lot to explore it yet. I am wondering if I can forward the store url when there are only one store within the MaxDistance radius.
Thanks in advance.
Hi Bjorn
Great work. I have a simple request which is can you add new descriptions to the data fields and can you customise the pin locator? Sorry basic i know but i’m still feeling my way around this new world of code.
Is there any way you could build in options for the user to be able to select the number of results, the radius, and select either Miles or KM – as options next to the search field?
Hi Bjorn, I have a need to limit the zoom levels, I’ve tried adding maxZoom and minZoom to the map options and it’s not working. Do you know of any reason it wouldn’t work with jquery.storelocator.js?
I was able to make this work in jquery.storelocator.js by adding “minZoom: 7, maxZoom : 14,” on line 654.
Hi Bjorn, thank you for the plugin.
I need a small help. I want to make the map to point to the closest location when someone makes a search. (Instead of showing the searched location, i want the map to show the closest location).
Hello Bjorn again, I have a simple question:
Within the template folder you have HTML files with some conditionals…what language are those?
Thank you!
That’s Hanldebars: http://handlebarsjs.com/
Hi Bjorn
I cannot, for the life of me, get your php->json examples to work. I would really like to make this plugin database-driven so this is important for me. I have tried with mysql, mysqli, and pdo connections, as well as directly copied your code replacing only my database credentials. Nothing comes up or is generates errors. Please help! can you post working php code that queries a db, and outputs all of the results in the correct json format?
I’m desperate, any help would be amazing.
– Shannon
Hello Bjorn!
Thank you for this AMAZING plug-in! It’s great to see that you are responding to questions still after a couple years as well.
I would like to know if it is possible to make the phone numbers clickable links so a smartphone user can click to call.
Thanks in advance for your help!
Yes, that’s as simple as updating the appropriate templates in the /templates folder with a telephone link. Edit: the rel=”nofollow” is automatically being added but you could leave that in as well.
I have read everything that pertains to color differentiated markers a few times. I have implemented the IF cat THEN … model as explained. I cannot get it to work. I know there is one working instance reported; are there others? I suspect there is some JAVA scripting detail that escapes the perception of the novice (me). Can someone help perhaps?
I’m planning on releasing the next version of the plugin this weekend and it’s got this built in. Check back for a post on version 2.
Wow, thanks for this!
Hi.
Is there a way to set a new default location. By default I would have on default location. And thats not a problem 🙂 But if I f.x. creates a link “France” I would like to change to default location, so the map shows France.
Please help 🙂
Hi,
Facing a problem when we open it a more than one time without clearing the cache.The problem is that zoom in zoom out is not working .So i have added one class for first to click auto matically on load but its not working for the city those have a single store.Please help me what i have to d init.
Great plugin! but how can i easily convert an xls or csv file to an xml that has the same format as the one you provide? I tried online converters, but the xml file always comes out looking different than yours with the <marker name=
Any help is appreciated!
Wayne I can help with this as I’ve had to do this for my project. Shoot me an email (matthew@perkpanther.com) and I can send you my file along with some simple instructions.
Hi Matthew, I know this is a year old, but I’m stuck in the same spot as Wayne (i can’t get the xml to look like <marker name=). Could you help me out thanks.
Great job!
I only have one problem.
Since the new plugin is the maxdistance-example.html not working properly like before.
I have tried to combine the maxdistance with the pagination but i wont get it work.
I hope that you have a solution because the oder version was working great but without the pagination.
Ok, yeah that settings combination doesn’t seem to be working on my end either. I’ll try to address this within the next week.
Thanks for your reply!
I’ve also tried the pagination example itself with a sql database
but with 125 results the script is hanging up my browser because it’s slowing down.
By choosing the pagenumbers for the first time after resulting it works fine
but by returning a page my browser doesn’t responding anymore.
Jeroen
The pagination and maxDistance bug should now be fixed in v2.0.4. As for your second question, you may want to consider returning less results to the end user. The pagination can get a bit slow with several results because the map has to reset for every page turn.
This is one of ‘if not’ the best Google maps plugin I’ve come across.
Im trying to load data in from a php/mysql file and out put in json – I test the php on it’s own and all that is output is null,null.null.null, null
Ive set the dataType to json and the correct datalocation for the the php file in the js settings – is there anything else I should be doing to get it to work?
Bit stuck on this, many thanks.
I figured it out – it was json encoding issues with utf8 and slightly reworked the output – seems to work for me, just trying to get it to work with the search distance version.
I added
$mysqli->set_charset(“utf8”);
just after my database connection.
Thanks for the awesome plugin Bjorn. Is it possible to build a map from the JSON retrieved from an API query?
I don’t see why not. You may need to use JSONP or if the JSON isn’t in the right format you may need to parse it and create a new JSON source.
Hi Bjorn,
I would like to congratulate and thank you for both making a fantastic plug-in and for making it available.
Could you (or someone on here) tell me if its possible to make the marker used for geolocation dragable and only show stores within a set radius?
Thanks
You might get some ideas from the following issue on Github: https://github.com/bjorn2404/jQuery-Store-Locator-Plugin/issues/18
Hi Bjorn,
Thanks for getting back, I’ll try that soon. However, I am struggling with something else at the moment – I’m using the autoGeolocation/maxDistance and would like the Enter Address or Zip Code: text box to pre-load with the users current address/postal code/lat-lng, so that they only have to hit the submit button. Or even better have the map load with the markers from defaults such as users current location and whatever is set as the miles value.
Hope that makes sense, any help appreciated.
Also I have downloaded the latest version today and was trying out the directions function and noticed that I got between 2 and 7 close buttons when the directions list was loaded, any of the button closed the directions list and returned to the main screen.
Regards
when using the max distance option on the demo, and performing a search for example Edina, MN, the returned results do not show or update in the side bar. Console logs an error:
TypeError: locationset[y] is undefined
var point = new google.maps.LatLng(locationset[y].lat, locationset[y].lng);
Wow, thanks for pointing this out. I can’t believe I missed this and it’s probably been a bug for a while now. I was using a nearby zipcode for testing instead of Edina (even though my example says to use that) and wasn’t seeing the error. I just pushed up version 2.0.3 with a fix and it should be working fine now.
Thanks for the update ! I’ve integrated this plugin with $smarty using a modified version of nearest locations mysqli. Few quirks needed ironing out but overall performing well!
Hi – I love this plugin. There’s a way I’m trying to extend it, though, to combine it with tabletop.js (that turns a Google spreadsheet into XML data). Is there a way to feed XML data that’s been generated in real-time to the locator? I’m generating an XML string like this:
markerxml = $.parseXML(markerxmlstring);
and then trying to get storeLocator to use that data as a success callback on the tabletop script; this (below) throws a syntax error:
$(‘#map-container’).storeLocator({
‘dataLocation’: markerxml
});
It’s not currently built in but it’s not too difficult to do with a couple of modifications. Comment out the entire AJAX request in the getData method and below it return the XML that you’re passing in.
Then you’ll just want to search for:
and replace the deferred method by just setting the data variable to (remove the bracket and parenthesis around the entire block of code – ex: line 1843 in version 2.0.4 that I just released):
If I’m remembering correctly that should do it. I’ve had to do this for a company and someone else has requested the live data as well, so I should probably add it to my list of things to add.
There appears to be an error with your error alerts. If you go to your demo and type in an invalid zip or postal you get a console error:
Safari: TypeError: undefined is not an object (evaluating ‘_this.settings.geocodeErrorAlert’)
Chrome: Uncaught TypeError: Cannot read property ‘addressErrorAlert’ of undefined
I need to implement error handling and this is holding me back. I’m changing your plugin code for our implementation but you may want to fix it.
This should now be fixed in v2.0.4.
Thanks Bjorn Version 2.0.4. is much better!
The maxdistance and pagination examples works both and combined.
There’s only one strange thing with the pagination.
When you’ve got more than 8 page’s the script hangs by going to page 8 by the 8th click on ‘next page’ and then my browser doesn’t responding any more.
Before hanging you’ll see that it begins to slow down by going to page 7.
It doesn’t matter how much results you have on each page. Even with one result on each page.
Thanks in advance for your help!
Yeah, I’m pretty sure the slowness has to do with resetting the Google Map so many times, especially if you page through them quickly, but I’ll look into that.
I have almost got everything running as I would like, but I’m having some difficulty with inlineDirections. When I run the example inlineDirections it runs fine on wamp, however when I create my own XML it doesn’t work, clicking on the Directions link causes all the markers (except the origin) to disappear but doesn’t show the directions panel or the map directions. I have tried it with both XML and JSON files that I have created from my database.
I was struggling with XML format at first so I have included a php script that outputs the XML like the one in the example. If anyone wants to use it just run the php script on localhost with wamp and it will create a file called locations.xml in the same folder as the script.
Thanks
Sorry, I don’t seem to be able to post code. If anyone is interested let me know and I’ll email it.
Hi Bjorn
This looks great. Thanks very much.
Just a question – How do you use the options.md file? I cant find it referenced in any of the code anywhere.
Im most interested in the categories feature – but if I add them in manually into the category-markers-example.html only one of my 4 categories shows up and I cant make the options.md file work properly. Sorry for the question -but Its got me stumped
The options.md file is a readme file that lists all the available settings you can use with the plugin. Please see the HTML example files in the dist directory on how use some of them.
Hi Thank you for the great plugin.
What should I do to add a fax number in the location list? Tried editing the template but added the same number in all of the addresses
How can I add an image in the info window description?
How can I disable the popup message that says “sorry the closest store is more that 60 miles etc…”
Tbanks
For your first question you need to add the fax in all fields in the xml.
2nd question read tutorial
3rd question change ‘distanceAlert’ : -1, in store jquery.storelocator.js
Where in the tutorial does it say that? You didn’t read the tutorial? How so you add images to the the info window?
Is anyone else having an issue with Internet Explorer not sorting the values correctly (through the sort_numerically function)? I get the correct distances, but the store list on the left doesn’t update to have the nearest location on the top. It works correctly in Firefox and Chrome. You can see my store locator at http://www.afstores.com/Store-Locator
Any idea how to slow down the sliding when changing between stores? Now it just like the map appearing right away and I would like to see the sliding effect.
The panTo() Google Maps API method only takes a LatLng parameter. It looks like you can do a zoom out and then zoom in if you’re wanting something different.
Hi thank you for nice plugin.
I would like to have two lists on one page.
I have two tabs, one for stores and another for offices, how to have two lists on one map?
Please advise
thank you
Does anyone know how to split the lists?
At the moment the list and markers are fed from the templates so it is easy to add or subtract what is shown, however, I would like to split the lest view. I would like to have the contact and opening hours details hidden in the list (easy enough) but have a link that displays a pop-up with the hidden details.
At the moment, whenever I try to wrap the elements in the template page with something else the list on the map page goes blank.
Any ideas appreciated
OK, another thought on this – is it possible to have the store information show up when you click on the map marker? So if I click on marker A only that store information appears in the list, marker B shows the store information for that marker and so on……..
Hi Bjorn,
Thank you for sharing this wonderful plugin.
I am trying to use my database with the plugin and using different marker for each category.
Is there a way to redefine the [category] name to mine? Your is specifically specified as category, but my table is define under loc_cat?
Thanks.
Also how would you go about with markers on same lat/lng like there 2 shops in same mall?
How do you change the font of the stores list? I have changed the font reference in almost every section I can find, but the stores list seems to not want to change. The label on the map shows up as arial, but the text at the top and the side list all show up as times new roman
Use browser developer tools to inspect the element is your best bet.
hmmmm – I did give that a try, but it didn’t give up any secretes. still confused as to why its showing a different font
Not sure where you’re getting Times New Roman from but the main font family is set in the .bh-sl-container class.
Hi,
Happy New Year All!
I was wondering if it would be possible to have a mini map displayed next to each location rather than a large map with all location?
Is this possible?
Great plugin!
Cheers
Loading that many maps at once is going to slow down the page quite a bit. I’d recommend taking a look at the Static Maps API, which you could set up to just show an image of the location on a map. However, I’m not sure if that’s kosher with Google’s TOS – basically, you have to show a map if you’re using the geocoding API (the plugin uses it to geocode the user’s location). Not sure if the map images would “count” or not.
Hello
First thanks for your awesome plugin. It helps me alot.
It works perfectly but i want to group/sort the store by city. I have a .xml file which gives the list of location in complete state but how can i group/sort it as per city.
Thanks
If you look at the categories example file I think that includes what you’re looking for.
Really nice plugin!
I have some questions:
Can I use custom styled maps? If yes, can you give/show me a simple example how to integrate with your plugin?
Can I change/override the handlebars?
thanks!
Hi Bjorn,
thanks for your wonderful script and your support. I got one question: Is it possible, that the template location-list-description.html gets the value, which the user used in the search-field “bh-sl-address”. How can i achieve, that i can pass this value to this template?
Thanks in advance,
Ralph
Hi, when I use locations in the UK it does not show the distance to these places in the results, nor does it show ‘Get directions’. What am I doing wrong?
Thanks
Are all of your locations geocoded? Also, I’d check the format of the addresses in your data and add country to the addresses if possible.
Thanks. Realy nice and awesome plugin.
Hi,
I’m trying to use with more than 100 locations (132 to be exact) and does not display the results, there is a limit of locations?
Thanks!
No, I would verify there there isn’t an error in the data that you’re loading. If you’re using XML check an XML validator, etc.
Hi Bjorn.
Thanks for your hard work.
Same issue as a poster above – How do you change the font of the stores list? I have changed the font reference in almost every section I can find, but the stores list seems to not want to change. The label on the map shows up as arial, but the text at the top and the side list all show up as times new roman
Any help would be appreciated!
Hi Bjorn
Great job!
Is it possible to search on store names? Name search is only searching for locations?
The nameSearch option allows you to search all the data based on a specific attribute – it uses “name” by default but you should be able to set it to any attribute in your data with the nameAttribute option.
Bjorn, we’re big fans of this plugin. Thank you.
Quick question: on our new dealer locator, we have a product category drop-down list that changes the URL of the JSON web service, allowing category-based filtering. Once the locator has been instantiated, it doesn’t seem to allow us to reinitialize with a new dataLocation value, and I don’t see a way of updating that value. Is there a simple way to update the dataLocation URL of an existing instance, or an easy way to force the map to reinitialize with new options?
-Joe
Well, you should be able to destroy and then init again with the dataLocation setting change but it would be easier if you could combine the data and differentiate with a category.
Hi Bjorn,
What’s syntax for replacing the default markerImg. I simply want to replace the default marker with another one but I couldn’t find any example or documentation on what the markerDim expects as a value
I tried
‘markerImg’ : ‘../assets/img/pin.png’
‘markerImg’ : [‘../assets/img/pin.png’, 32, 49]
even
‘markerImg’ : {‘../assets/img/pin.png’, 32, 49}
Also what format does markerDim need to be?
Thanks
markerImg is just the path to the image. markerDim should be an object – options descriptions are in the options.md file and there’s an example of the markerDim in there.
Does anyone else have problems with the form on https:?? When I use this plugin and access the page via https:, the page simply reloads itself after submitting the address. For the life of me I can’t figure out why this happens or how to fix it!!
Does your console show anything?
Very great plugin!
I miss one option or i cant find it. I have a text-input and typed in plz or address and click on submit.
The modal-window opens. For this very first time or init i want to add the list-focus on the founded li and
an other marker-image for the founded address and an opened infowindow for this marker.
Is this possible?
How do we get this to work on smartphones? The Google API doesn’t resize….
Set it up with CSS and change the container to be responsive. See the included Bootstrap example as one method.
Hi Bjorn, your plugin is great.
I’m beginner to jquery programming.
First of all I apologize for my bad English.
I’m trying to implement filters on categories based on your example “categories-example.html”.
I,ve insert 4 checkbox with the categories
But if you select two or more filters the result is always nothing found (even if the results should be).
I need to have the result of all the checkbox checked… es: if i check restaurant and bar i need to have all the restaurants and all the bars.
What i can do?
Thank you
I’m in the same boat. Anyway to fix this? Also I seem to be getting a bug where the map stops working when I use customs markers and the categories together.. Soon as I take them out it works fine.
I’m also looking for a way to return all stores that fall under any of the categories selected. I will let you know if I find a way but I would love to know if someone else already has a solution.
The filters are currently only inclusive and the filtering is set up with regex. I’ve had a couple of additional requests for this including these so I’ll see if I can work it into the next version.
I’ve now added this as an option with ‘exclusiveFiltering’ in v2.0.6.
Hi Bjorn! Thanks a lot.. Great Script! i’d like to know if is possible to change stylessheet of a single XML element. For example i’d like to have a different style only for the first ” loc-name restaurant” appeared on my list; or if is possible to change every with different images. i hope to be clear (my english is not so good 🙂 ) thanks!!
I’m not sure if I understand but I think what you’re saying is you want change the CSS for the first restaurant in the location list. To do that I would add the category to the list item in the location-list template . Something like:
Then with CSS you can do something like this Stackoverfow question.
AMAZING PLUGIN…! saving my butt using this. I was just wondering if there was any way to have at ” ‘fullstart’ : true ” all the locations listed…. Then when search is done only say 20 are listed? I’m running into a problem where I have featured locations and if I have all locations on start then when they search they have go through all 40 featured locations before they see any that are relevant to the actual location. The reason for wanting to show all locations is because it looks awesome to see all locations across the country. Thanks for any help you can send my way!
I have max 4 featured locations in 1 city at a time so if you could maybe show me how to remove the remaining 10 featured from the list somehow that would be great too.. 😀
I would use maxdistance search but the entire map craps out if you hit search without anything typed in… So not really an option.
This a fantastic plugin. I have featured this to some of my bootstrap framework project performances are brilliant. Superfast json call backs with prompt results display. I have seperately included your details as original author of this plugin – credits for you Bjorn! It would be useful if there is option to control grid view and map view listing. I have archived this seperatly using jquerys.
Nice work. Good luck.
Thanks, Bjorn for the awesome plugin. It was running well for me using the json option but I can’t figure out how to add category filtering while using json data. My code is below, any pointers would be appreciated!
$(function() {
$(‘#map-container’).storeLocator({
‘maxDistance’: true,
‘dataType’: ‘json’,
‘dataLocation’: ‘data/locations.php’
‘taxonomyFilters’ : {
‘category’ : ‘category-filters-container1’,
‘features’ : ‘category-filters-container2’,
‘city’ : ‘city-filter’,
‘postal’: ‘postal-filter’
}
});
});
I was able to get this to work by modifying the datalocation in the actual plugin rather than the plugin call. I know it is not the ideal method but the category filtering now works with my json data.
I got it to work in the plugin call. I was missing a comma ‘after data/locations.php’. I also updated ‘category’ and ‘features’ to match the column names in my datatbase. This is the first webpage I have worked on and it has been a great learning experience.
Nice plugin, just achieved what i want,
but stuck at one point of zoom level,
can you please guide how to increase by default zoom level in map when we launch.
Not sure if this will reset the zoom level you are looking for but the options.md file (referenced on this page) lists the default zoom at 12. You should be able to adjust that in the plugin call. There is also helpful zoom level info in the comments section of https://www.bjornblog.com/web/jquery-store-locator-version-2-0-0-released.
How would I get access to change the overridden options? So, I want to allow users to change how many stores they search for, use a select box with half a dozen values. How would I use a sLimit variable to update the storeLimit option in the storeLocator options list?
Hi Bjorn.
Your plugin has been a lifesaver!
I just have one issue with filtering. I am have using taxonomyFilters to sort the map listing but I have also create an additional event for the taxonomyFilters checkbox. This additional event hides some content in the items displayed in the map listing. I have both filters working perfectly individually however they do not work together. I have tried adding my event to the callbackSuccess which works if I disable the taxonomyFilters but unfortunately only the taxonomyFilters work if both are enabled.
I know this is customizing beyond the plugins intentions and I would be more than happy to contribute to the cause.
The current code I have is below. Any suggestion would be much appreciated.
$(‘#map-container’).storeLocator({
‘taxonomyFilters’: {
‘category’: ‘category-filters-container1’
},
‘callbackSuccess’ : function () {
<>
});
}
});
Ho Bjorn,
great plugin! I’m trying to get the autocomplete feature implemented to receive search suggestions into the search box, like described here:
https://developers.google.com/maps/documentation/javascript/places-autocomplete
Do you have any hints?
Cheers, Robert
Hey Bjorn,
I know you hear it all the time but THANKS AGAIN for this plug in. It is a real life saver.
I didn’t have a question just wanted to say thanks.
Best Regards,
Lee
Hey Bjorn,
First of all I want to thank you for the script – great job 😉
I’ve seen this question asked a three or four times in the comments but can’t see an answer and, no matter what I try, I can’t get it to work.
What I’d like is when the map is first loaded, all locations are shown.
Then, when the search function is used, I’d like only 3 locations to be shown in the results. I can set the storeLimit to 3, no problem, but we have 11 locations.
I can set fullMapStart to true, which zooms out and shows all locations, but is there a way to make fullMapStart independent of StoreLimit ?
If I set fullMapStart to true and storeLimit to 3, for example, on my html page, it will still read the storeLimit setting of 11 from within jqueryStoreLocator.js
Or is there a way to change the storeLimit via a .click function perhaps ? I’ve tried changing storeLimit onclick with myOptions but once the map is drawn and the storeLimit is set, I can’t seem to change it again.
Kind regards
Paul
Great work. This is working from my machine but not from server? Help Thanks.
Can you provide any more details?
Great plugin. But It has a problem with IE9 and iOS Safari when loading template files from another domain. It always displays this message:
Error: Could not load plugin templates. Check the paths and ensure they have been uploaded. Paths will be wrong if you do not run this from a web server.
I appreciate you help! Thanks
Do you need to load the templates from another domain? You may just want to do inline templates instead – set the listTemplateID and infowindowTemplateID and set up the templates like the second example on the Handlebars site. Otherwise, if you absolutely have to do cross-domain, you’ll need to enable CORS on the server.
Hi Bjorn, first: thanks for putting this script online.
But I also get this message “Error: Could not load plugin templates” and no maps are displayed. Im not that much of a coder could you please explain what you mean with “set the listTemplateID and infowindowTemplateID and set up the templates like the second example on the Handlebars site.” or write a short example? Would really appreciate it.
Cheers
Hi, I have been trying to put an Image in the list-description. So far I have used img=”” in the Locations.xml and I have tried to use [[img]] but with the correct brackets as the location-list-description. I cannot get the image to view in the description boxes.
I have also tried to add lightbox to the description box which has partially worked…
Do you have any suggestions on how to add a larger image into the description? I think I may be missing some code I need to be adding to the storelocator.js….
Any help is appreciated!
Thanks
What are you putting in the XML? The filename? The full path to the image? You have to put the full image HTML tag in the template:
how can i embed a link on the csv for each listing like you are doing, excample chipotle. i am using the latest version and i see you have a demo with working hyperlinks but the package doesnt display this. please advice
If you look at the data files you’ll see that I’m using the “web” attribute for the location URLs. If you’re using a different attribute name you just need to update the template files with yours. /dist/assets/js/plugins/storeLocator/templates
another query i have, is there a way to create 2 or 3 different markers based on the category they are in. like red pins and blue pins.
Yes, see the “Custom category markers example” linked in the demo section in the post above.
Thanks for the awesome work. I had one question – what is the best way to pass the defaults / options dynamically – we have a need where the defaults may need to be changed depending on a user action on the page. Is there a simple way to do this?
Hi, and thanx for the plugin it works great!
i cannot get the regionID “bh-sl-region” parameter to work,
and tbh “ID of the region input form field for country region biasing select field.” in options description is a little confusing , what do you mean by “input form field select field “? ? a select field and an input are two diff things.
this is the html markup i am using , that should work right ? i am used a select field with ISO-3366-1: Alpha-2 Codes , I also tried all other possible country codes including numbers and full name values,
Afghanistan
... all the other options in between
Zimbabwe
Go
the store locator with geocode and also enter input address or zip code still works but the select field does nothing , is there something i have misunderstood ?
Hello congratulations for the plugin .
I have a question you can place the marker on the map using your geolocation ?
I have the latitude and longitude , and I set in the fields and defaultLat defaultLng but do not see the marker .. how can I do ?
thanks
I think you’re looking for the originMarker setting. The defaultLoc/defaultLat/defaultLng settings are for opening the map with a default view basically, without having to enter anything into the form fields.
Thanks for the great work on the plugin. I’ve got it all set up and working perfectly on my development site. The problem I run into is when I take that same code and place it within the template on our new cloud provider (NetSuite). Their system loads a lot more javascript resources and I end up getting google is not defined because it’s not loading asynchronously.
I’ve been trying to research different scripting tricks to get it to load once everything on the page is loaded but nothing has work so far. Here is my initial code:
jQuery(function() {
jQuery(‘#map-container’).storeLocator({
‘mapSettings’ : {
zoom : 0,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDoubleClickZoom: true,
},
‘addressID’: ‘bh-sl-address’,
‘locationList’: ‘bh-sl-loc-list’,
‘autoGeocode’: false,
‘inlineDirections’: true,
‘fullMapStart’: true,
‘maxDistance’: false,
‘slideMap’: true,
markerImg: ‘assets/img/flag-marker.png’,
markerDim: {
height: 32,
width: 32
}
} );
});
Any ideas on how to get this to work? Below is the latest attempt based on information found online:
function initialize() {
jQuery(‘#map-container’).storeLocator();
}
function loadScript() {
var script = document.createElement(‘script’);
script.type = ‘text/javascript’;
script.src = ‘http://maps.googleapis.com/maps/api/js?v=3.exp’ +
‘&callback=initialize’;
document.body.appendChild(script);
}
window.onload = loadScript;
Still ended up with ‘Uncaught ReferenceError: google is not defined’ after handlebars.js and storelocator.js loaded.
Appreciate any insight anyone can provide.
Thanks.
Dwen
Hi Bjorn…first of all, let me thank you very much for such beautiful piece of code.
I have managed to setup the locator to customize the 99% of my needs, but I have one question that I’d like to share with you.
This goes for when you disable the distance alert:
If the client that will use the locator doesn’t have too many locations, it’s confusing that after the search, the map centers on the users given address. Suppose you have like less than 100 locations, then not all users will have a very close one.
If the alert is set then the map will center on the correct area (the closest location area) after you click ok, but if the alert is set to -1 the map will stay on user’s provided address with nothing around it.
Basically, what I’d like to achieve is to have the same behaviour than when you click “ok” on the alert but without having alerts.
Is that possible? I appreciate in advance any lead to find a solution.
Thanks so much.
Setting the zoom to zero (0) in the mapSettings object should do the trick.
Hi bjorn,
Its really very good code. I am sure that locations.kml is in the directory as it works fine in my local server. But when I host the site and click submit nothing is displayed.
I am sorry for asking this silly question because i am pretty new to this, it would be appreciated much if you help me.
I seem to have an issue with the plugin, when I click on the submit button, it sends me straight to the homepage of my mobile app. Any ideas why this would be occurring? I’ve looked though the storelocator.js and I can’t seem to see any issue there.
Thanks for this. This is awesome. I do have one question though. I am trying to use autogeocode with the taxonomy filters but I am running into a little problem. When the map originally loads the distance away for my locations is correct, but when I select one of the filters all the results take on the same distance away. Is there anyway to correct this? Below is the code I am using.
$(function() {
$(‘#map-container’).storeLocator({
‘autoGeocode’: true,
‘taxonomyFilters’ : {
‘category’ : ‘category-filters-container1’,
}
});
});
Hi Bjorn, I am trying to let show the first search result on the map instead of the location of the entered result after people click on submit. I tried to call the click function in the processdata but didn’t work. Any help would be much appreciated.
Hi Bjorn,
Thanks so much for your amazing work.
Just wondered if it was possible to have different marker image depending on the data being pulled through from a JSON.
For example, I have “type”:”retailers” as way to determine which object I want but I want to show a different icon for this.
I’ve brought this through as a data- attribute in my HTML.
I’ve been playing around with your markerImage function…
markerImage: function (markerUrl, markerWidth, markerHeight) {
var markerImg;
// User defined marker dimensions
if(typeof markerWidth !== ‘undefined’ && typeof markerHeight !== ‘undefined’) {
markerImg = {
url: markerUrl,
size: new google.maps.Size(markerWidth, markerHeight),
scaledSize: new google.maps.Size(markerWidth, markerHeight)
};
}
// Default marker dimensions: 32px x 32px
else {
markerImg = {
url: markerUrl,
size: new google.maps.Size(32, 32),
scaledSize: new google.maps.Size(32, 32)
};
}
return markerImg;
},
But can’t get it to show a different marker image.
Any hints?
Thank you.
Ben
Hi Ben,
Would this be different from my category markers example?
Ah! Thank you! I have used this to get my results. I didn’t realise this setting existed before I posted.
Once again, great work!
Thanks.
Like everyone else, love the plugin.
Any chance you could provide an example of using callbackBeforeSend ??? Everything I tried threw an error.
Thanks for the plugin. Can you please help me with the issue? I am trying to search based on the location and outputting the result on the modal window. It shows up the location I am searching for on a modal window which is exactly what I want but I also want it to automatically pop up the info window on the marker without the need to click the marker Icon? This is quiet important… My next question would be can I have different marker icons for each location similar to having icons for different categories.
Thanks,
Monica
The Category filtering example doesn’t seem to work, please get back to me, this would be a perfect solution for me if it was working…
Thank you for your great work!
In the Category filtering example, when i filter 2(or more) categories e.x Restaurant, Cafe, the plugin tries to find a location that belongs both in Restaurant and Cafe category.
If i could transate it to a sql query the plugin default action is this:
SELECT location WHERE category=’Restaurant’ AND category=’Cafe’
How can i accomplish the below?:
SELECT location WHERE category=’Restaurant’ OR category=’Cafe’
Thank you in advance,
El Psy Congroo
Please see the exclusiveFiltering option.
Thank you very much,
Works like a charm!
hey bjorn.
i can use your plugin when i used static page php. but when i need to use on codeigniter it always give an error like this
https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xtf1/v/t1.0-9/s720x720/11745765_10204817556135501_140501912915485753_n.jpg?oh=cba4901b78c5fb860d86de382fcf17f1&oe=564BC91B&__gda__=1443844874_9a30efda52766ddd238afb3085e6baf1
here the firefox element says:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help http://xhr.spec.whatwg.org/ jquery-1.11.2.min.js:4:0
A call to document.write() from an asynchronously-loaded external script was ignored.
thanks for helping 🙂
Are there any limits to using this store locator? Like how many look ups you can do? (Assuming the locations are pre geocoded.)
Thanks!
Yes, the plugin uses the Google Geocoding API to get the latitude and longitude of the user’s input when the form is submitted. The geocoding and map limits are outlined in Google’s API documentation.
Do I need to give it my browser or server key if I get close?
You can sign up for an API key and then you’d just append it to the end of the Google Maps script include: http://maps.google.com/maps/api/js?sensor=false&key=API_KEY
Thanks for the help!
I am using a store locator jquery plugin from https://www.bjornblog.com/web/jquery-store-locator-plugin for my website and everything works fine but what I want to add is once the store location list is generated, the first one on the list is automatically clicked.
In the Jquery, I can see there is a section controlling the click on the list. It has some parameters.
// Handle clicks from the list
$(document).on(‘click.’+pluginName, ‘.’ + _this.settings.locationList + ‘ li’, function () {
//do the work.
}
The pluginName is ‘storelocator’ and _this.settings.locationList is ‘bh-sl-loc-list’
the elements of the list shown on the html
I tried the belows but obviously nothing worked, what sort of syntax I should use to maybe pass the parameters and call it? Much appreciated.
document.getElementById(“.bh-sl-loc-list:first-child”).onclick();
$(‘.bh-sl-loc-list:first-child’).trigger(‘click’);
$(‘.bh-sl-loc-list:first-child’).trigger(‘click.storeLocator’);
$(function() {
//$(‘.bh-sl-loc-list’).hide();
$(‘#map-container’).storeLocator({
‘dataType’: ‘json’,
‘dataLocation’: ‘../wp-content/themes/subway-clone/data/locations.json’
});
$(‘.bh-sl-loc-list:first-child’).trigger(‘click.storeLocator’);
});
});
$(‘.bh-sl-loc-list li:first-child’).trigger(‘click.storeLocator’);
I also tried this but still nothing happening 🙁
figure out myself, and It is just a very very nice plugin!!!!!
Any idea as to why I get a “Cannot POST /” page after I hit submit with no console errors?
Just a guess but if you’re using a ASP.NET CMS you should not be using HTML form tags and using the noForm plugin option. I’d also make sure all the JS is loading properly.
Thanks for the great plugin, Bjorn. I’m curious if there is a way to create lettered icons using a custom marker image?
Just wanted to say thank you! Amazing project, helped me a lot and saved me a ton of time. Thank you!!
Hi there. I think I am using the library correctly, but I get an error when I try to register the plugin with the map-container:
Uncaught TypeError: undefined is not a function at $(‘#map-container’).storeLocator({…});
I have put this script at the end of my page and am loading jquery handlebar and storelocator files before it. It could very much be that the script is being executed before the files are being loaded – but it could be something else that I am missing out. I am trying to create a website using MVC. I will be loading store location from an xml file.
I did have another question – is this solution responsive on a mobile device? That is, would the solution work on tablets or mobile phones?
Please see the Bootstrap example which features responsive styling.
There were some examples how to open the nearest store automatically after the search but they do not seem to apply to the current version.
What is the best way to do this?
Hi, i try to use your plugin and try to search a nearest store of australia using the zipcode 2001 – 2005 and it returns all the stores in the australia. It suppost to be return only the stores with in sydney. Do you have any ideas how to fix this issue?
Are you using a range of zip codes or are you trying 2001 through 2005?
Is there a possibility to add an image in the information box through xml or add custom markers for each store?
Sorry for the repeting question. I found about the custom makers. If you could make a brief explain on how to add an image on the info box I will be greatfull. Thank you!
You can add any attribute to the data and then update the Handlebars template file to display it. For example, locationImg=”http://urltotheimage.com/image.jpg” in locations.xml and then {{locationImg}} in the infowindow-description.html file.
Thank you very much for your reply!! 😀
Hey, Bjorn, I’ve been tearing my hair out trying to implement a rawdata json object, but haven’t been successful.
loading the json as a separate file works just fine, but my current project has a variable created inside the page as var CECLocations @Html.Raw(Model.LocationsJson) like this:
var CECLocations = {
“Locations”: [
{
“id”: “1855”,
“name”: “Store1”,
“lat”: “33.7728”,
“lng”: “-117.920502”,
“address”: “13101 Harbor Blvd.”,
“city”: “Garden Grove”,
“state”: “CA”,
“postal”: “92843”,
“phone”: “(714) 539-4332”,
“hours”: “Mon-Thur 10am-9pm Fri 10am-10pm Sat 10am-11pm Sun 11am-9pm”
}]
}
I’ve tried stripping down that into a raw string and injecting it in dataRaw like this:
var jsonStr = JSON.stringify(CECLocations.Locations);
$(‘#map-container’).storeLocator({
‘dataRaw’: jsonStr
});
… but all I’m getting when launching is “GET http://www.z4digital.net/temp/test/locations.xml 404 (Not Found)”
Can you tell me if rawdata json is possible, and if so, what am I doing wrong? Thanks!
Actually got this work now. Downloaded two version of your plugins, the one I had was old and didn’t support dataRaw. I now have another question: how do I start with showing just 3 stores, and have a function that append 3 more locations to map and address result in the same page? would pagination be modified slightly for this?
Hello,
How i can display some default sorting of locations, if user blocks the automatic geolocation detection. in browser?
Hello,
how i can stop google map scroll on mouse wheel.
i.e : scrollwheel: false
The mapSettings option accepts any standard Google Maps settings but make sure to include zoom and mapTypeId if you update the setting. See the Bootstrap example for a code example.
Hey Bjorn, this Bootstrap link points to a V2 link (http://bjornblog.com/storelocator/v2/bootstrap-example.html) …do you have an updated version of the plugin?
No, that’s v 2.x (latest version) of my plugin. The example file uses Bootstrap 3.1.1.
I’m trying to give the plugin an option to re-initiate the plugin, from showing pagination of 3 items per page, to show all locations on one page. Is there a current options to do that already? I tried $(‘#element’).storeLocator(‘destroy’); and then reiniating it, but it doesn’t work after the first instance is destroyed. Please help! Thanks!
looks like simply switching ” _this.settings.pagination = false;” automatically destroy the pagination and do exactly what I wanted. Is there a setting in the code for display markers by bounds? As in showing only groups of markers in the videw point, and auto update hide out of bounds markers, and show when the bounds change?
Hi Bjorn,
I’m using Maxmind Geo IP database to get a latitude and longitude from visitors IP. I then set this lat and lng as the default location. Our map has hundreds of markers and doesn’t look very good. I’d like to have the page load with a map at a specific zoom level but not display any markers until a search is made. Our locations are set with json. I’m attempting to access the google.maps object but new to javascript, I see I can do a console.log google.maps but I don’t see where or how to access the markers. When the page loads is there a method I can fire to clear markers or simply modify the plugin to not show on default locations?
Thanks
Peter
So, in case anyone else is having issues with the map not showing up at all, the ampersand (&) is an escape character in XML and cannot be used even between quotation marks. Make sure you do a find and replace if you have any in your data.