jQuery Store Locator Plugin
Warning: Invalid argument supplied for foreach() in /home/customer/www/bjornblog.com/public_html/wp-content/plugins/gravityforms/form_display.php on line 1726
Warning: Invalid argument supplied for foreach() in /home/customer/www/bjornblog.com/public_html/wp-content/plugins/gravityforms/form_display.php on line 473
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.
Hey Bjorn,
If we are using a json file, is there any way to keep people from navigating directly to the php file and see all the json records in their browser? I tried using htaccess, but then the map won’t populate either.
Thanks for any help!
I think I’d try using a cookie or session variable. Set a value when the visitor views the page and check that value in the other file before outputting the data.
Everyone who uses this plugin schould make a donation to Bjorn!
I will do!
This is a great plugin! Thanks for making it available.
I am having one issue: I’d like to load my XML file from a different domain, but I can’t get this to work. My XML always has to be hosted on the same domain for the script to function. Am I going crazy?
Looks like I’m running into the same origin policy. My site is hosted on Shopify, which means the page URL looks like http://site.myshopify.com but the assets are stored on http://cdn.shopify.com what can I do to get around this problem?
I ran into this same issue. Shopify is unable to add a cross origin to cdn.shopify.com for your asset folder, so you cant call in your .kml form there. Our workaround was to use Amazon S3 to host that asset, which allows you to easily set up a cross-origin policy for shopify.
Caroline @shopify also had this clever workaround idea:
“You could also have your client paste the content of his KML to a page in his shop, then use my solution here: http://stackoverflow.com/questions/8743045/how-to-create-an-empty-html-file-in-my-shopify-website.
Key point is to use {% layout none %} in the page template you’ll associate to the page. That solution speaks of an HTML file but the same is true if you need a XML, CSV file, any type of file which has UTF-8 content, including a KML file.”
Did you use JSONP to grab the asset from Amazon S3?
Wow okay, I finally figured this one out. Made a new bucket on Amazon S3 that contains the external resources. Used the CORS rules to allow GET requests, see doc: http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html
Now it works perfectly 🙂
Hey Bjorn, is there an option to add a google map cluster or any help on how i can add that to the map? Great work on this. Thank you
I haven’t done anything with clusters at this point. I can look into it.
Hi. Thanks for this. can you please confirm there are script errors after you click on a link (web address, which opens new window). I have checked this in Firebug across all your demos. Any subsequent click produces script errors.
Sorry, I’m not sure what you’re talking about. Can you be more specific and paste the specific error you are seeing?
Hello, really great plugin, thanks for creating this.
One thing I’m trying to figuring out though: I’m using Laravel 4 as framework and I have 3 different languages files that I use for my website. I would like to display the store locator map in the language they user prefers. Could you give me any suggestions where or how to start trying to accomplish this?
Cheers and thanks again!
You might be able to do this just by passing different options to the plugin. They aren’t documented above yet but there are options to override the text of each alert and the miles and kilometers text (look at lines 57 to 65 for the options names). For the actual location data you could have 3 separate data files or generate XML or JSON with the translated location data. If you have the country code available you can also add the region parameter to the Google Maps call for region biasing (step 4 above). There isn’t any actual text in the template files other than the Directions link – I should fix that and make it an option too now that I look at it.
Hey Bjorn, +1 on clusters!
Also it would be very nice to have the option of loading map styles and specifying custom markers so you can get away from the generic looking map. Does not look easily possible right now as markers paths, etc are hard coded – or do you have any samples?
Great work.
Yeah, I looked into adding custom marker options but kind of hit a dead end (if you look at the changelog I have a note about this in the version 1.4 description) in terms of the better options. You can change the markers without too much trouble but you would have to modify the plugin file – you’d want to check out the createMarker function that starts on line 781. There are also some comments above about doing some different thing with the markers based on category.
Also, I don’t know if you’ve been paying attention to Google I/O the past couple of days but Google did reveal the next version of Maps and it looks much better. I think they said it will be released in August.
Apologies – this is embarrassing. It seems its quite intermittent (atleast for me). I came back to it this morning, and I cannot replicate it. I will post again if/when i find the error.
Thank you for replying – I really appreciate it. And thank you for a wonderful store locator plugin!!
http://www.imagehousing.com/image/1131645
(copy paste of error from firebug ->)
Error:
http://maps.gstatic.com/intl/en_us/mapfiles/api-3/13/0/main.js/eval/seq/7
Line 14
It has come up – it seems an error to do with Google Maps api.
What i did:
– open the demo page – http://bjornblog.com/storelocator/
– search for ‘edina’
– click on the website url http://www.chipotle.com
– go back to parent page
– clicking anywhere produces the error
That’s strange, I can’t seem to reproduce this. A few things:
– Are you using the latest version of Firefox and Firebug?
– Can you also make these errors display with Chrome developer tools?
– Does it still happen if you close the Chipotle.com tab and then click around?
I’m having a problem with the latest version. In version 1.3.3 everything works great. However, in 1.4.4 the map never loads. Instead in the complete event the request parameter contains “parseerror”. I checked my JSON data and it looks fine. My initialization code is:
$(‘#map-container’).storeLocator(
{‘jsonData’: true,
‘dataLocation’: ‘map.php’,
‘storeLimit’: 5,
‘maxDistance’: true,
‘formID’ : ‘placesToPlay’});
Not sure what I’m doing wrong with the new version.
Thanks!
Floyd
Do you have an example somewhere?
Hello!
I was wondering if there was a way that I could have the website listing in the XML not actually list the domain, but when it renders, it says ‘View Website’ or something along those lines instead. Is that possible?
Thanks!
Yes, you’d just want to update the template files in the /templates directory. If you’re using KML as your data source update the 2 files that begin with kml-, otherwise update the other 2.
Hello,
Is it possible to order the list by the order in the xml file instead of by distance?
Thanks.
Sure, just comment out or delete lines 493 to 497. You’ll see a comment about sorting above it.
We are interested in being able to pan the map left or right and/or resize ( + – ) and at the same time virtually add new markers and listings to the map as we reposition it – using json calling listings from mysql database?? Any suggestions this type of implementation ??
In the create_location_variables(loopcount) function
why are both locationset[loopcount][2];
and
locationset[loopcount][3]; omitted
Thanks
steve
If you look at how the locationset array is set up you’ll see that those 2 are for the lat and lng. I figure that most people probably won’t be outputting this data to the infowindows or list.
for anybody wanting to push results to another page, christophers solution works (with jquery.noconflict()), but you may have to set the timeout delay from 2 to 10 in case you run into trigger loops. Also the php which the data is sent to by action=”filename.php” can simply be called from any cms page. Also there is no need to hide any forms or create new ones if you want to be able to search on the other page. If anybody needs help with this dont hesitate to ask.
Hi Paul Can you give me a sample push results to another page
Thanks
Hi paul i need your help to push results to another page
can you please helpme.
thanks
Hi Bjorn,
you explained to james how to add a different type for xml. Somehow I cant repeat the process for kml data. Is there a significant difference in how to go about it?
I am thankful for every hint.
solved
Hi Bjorn,
Thank you for the work put into this. I’m not great at the backend stuff so was wondering if you had a sample file of how the mysql database should be structured and also the php file that makes the connection and outputs the json. Spent 2 days now trying to do it and nothing gets outputted 🙁
Any help with this would be GREATLY appreciated. My store locator will have over 10,000 locations so is a mysql database even the best way do it?
It’s basically all above in the documentation. The screenshot of phpMyAdmin is a structure example and the PHP code is right below it. 10,000 locations is quite a lot but yes I think the database route is going to make the most sense. I’m not sure how the performance is going to be with that many – you’d probably want to put it on a fast server.
PHP:
Great script.
I was wondering if it was possible to open with the full map of North America, but not show any of the locations until someone searches.
Thanks
Sure, just add a basic map to the map div and set the slideMap option to false. Example that would go on the index.html file:
Hi,
I copied your code but it doesn’t work!!! can it maybe depends for Altervista.org (where I putted the folder with all the file and index.html)??? Thanks
Do you have a link to an example?
Sorry for didn’t reply but I resolved this first problem…it was a conflict between your jscript and another I had in my site…now I’m working to take data from database and change the list of details for eachone address, thanks
I have only one problem…i have errors in the scrollbar and the cloud on map with data’s inside…I can’t see them very well. Where I can control the view of them? in the .js?
Thank you so so much for the plugin! It works just perfect!
Just two questions:
a) you use “category” (array) and in the create marker () you have “type” as one of the parameters. Could you please explain those?
b) the reason I asked: I am trying to create a filter (ex: http://jiren.github.io/filter.js/)and I was wondering if you had some kind of filter in mind while you were writing the code, like (Mexican, Chinese) , (restaurant,bar), etc.
I am very new to programming and your code is just awsome! Thank you again!
Yes, so if you look at the XML data there is an example of category usage. All of the locations in the example are set to “Restaurant” but they can be anything you want. You can use these categories to filter, create different markers or display them in the infowindows and list. I have some instructions above on creating a drop-down select field filter:
https://www.bjornblog.com/web/jquery-store-locator-plugin#comment-15097
I loaded your original code and did the changes with maxdistance=false. Now I get no error, but no stores either.
Thank you for your replay.
Please bear with me. I have been trying to do this for a month …. I am really new to this.
Yes,I was using the code with distance.
I did the changes and I am getting the ‘distanceErrorAlert’. A couple of questions:
1. Does it matter if I am using Json, Xml or Kml? If NOT, I should just change the following in the respective method:
if(settings.maxDistance === true && firstRun !== true){
if(category=== selectedCat)
regardless of being in the json or xml or kml (I am using Json). If this is not right, please let me know.
2. The Html part.
Original code:
10 Miles
20 Miles
30 Miles
40 Miles
Change the “maxdistance” to “category”? Or leave it and add a new select box? Of course, instead of miles, restaurant, bar, gas, etc.
4. Can I have both, distance and category?
Thank you so much again for you kindness and patience.
Category is only set up to work with XML and JSON data. You will want to change the locationset array creation for your data method (the others won’t matter). You’re using JSON so you’d want to look at the if statement starting at 411.
You can use both the filter and the max distance option. Create a new HTML select field with the id of “category” if you want the code to match my example above. If you want to use both you would want to change line 412:
to
This is stating that we’re only including locations in the locationset array that are within the selected distance and are equal to the filter value.
Thank you so so much!!
It worked as soon as I stopped my confusion between json and xml, your data, my data :/ My fault.
There was a question up above about checkbox. It also works with
$(‘input:checkbox:checked’).val(); (more info on http://api.jquery.com/val/)
var checkedCategory =$(‘input:checkbox:checked’).val();
I changed “selectedCategory” to “checkedCategory”. I also added it in the settings, but I am not sure if necessary.
Two problems:
select option makes user to opt for only one (single option). checkbox: user may check more than one.
If we are comparing array to the Json/array (form database) to push the markers, how could you check for both bar and restaurant, both in Minneapolis (with or without handicap access etc.)? (thinking in dynamic database where people should choose either bar or restaurant, but not both. The solution of having bar & restaurant is not ideal, very restrictive.
Also, second problem, user has to choose all options available. Cannot leave any option / box alone, because of the &&. It sends the distance error.
Thank you so much again for your help and plug-in. Wonderful job and best plugin in the net!
my typo: (thinking in dynamic database where people should choose either bar or restaurant, but not both). I mean while inserting data into database. End user can choose whatever he/she wants, one or many. Sorry about the confusion.
Yeah, you’ll want to add some more validation in that case. First check if the field has a value and then if it does continue with the filtering. For the checkboxes, if there are just a few checkbox options you could just do something like:
If there are a lot you’d want to loop over them.
First off, this is a really great plug in, but maybe you can help with an issue I have. When I first downloaded it, the examples worked fine, however now I can’t get any of them to display any results, even after re-downloading? I have a JSON file that I would like to use, could I simply replace your locations.json file in the example? I am pretty new at this, so any advice would be great.
Thank you,
Dan
I figured out how to get the examples to display, still working on integrating my Json file, again any help would be appreciated.
Sure, you can overwrite the locations.json file with your own data. Also, make sure the JSON validates – you can use something such as http://jsonlint.com/
Great thank you. Will it work if I have different property names? I currently have id, address, city, state and postal. It is for a newspaper box finder, so I don’t really need the other properties. Is there anything I should know that is needed in the JSON doc? Sorry this might be more than you need to answer, but again any help is appreciated.
You’ll want to change where the variables are set for the JSON data to match what’s in your JSON file (starting at 391). For instance, you could change the name variable equal this.id. You will want latitude and longitude coordinates in the JSON file because of the geocoding limits that Google has in place (1 per second and a certain number in 24hrs). For the variables that you don’t need just set them to equal nothing – taking them out completely would be a lot more work (ex: var hours1 = “”;)
Hi Bjorn,
Great, great work on this plugin, it works awesome!
I do have one request, when you enter a zip code or address in the search box and hit submit the result takes you to the place you entered but I would like to have the result take me to the nearest place or top/first result in the left panel on the map.
Does this make sense 🙂
Many Thanks.
The results are ordered by distance from the entered location. You have to provide the data for the plugin to read: KML, XML, or JSON.
Hi Bjorn,
Thanks for your reply but what I was kind of hoping was a way where the map works like this:
http://www.argusdirect.com/find-distributor/
So it doesn’t take you to the place you entered in the search but in fact takes you to the first location in your list which is closet to your entered information.
Is it possible with a couple of tweaks of your code?
Thanks again Bjorn!
Oh, I see now. Yes, that’s easy. Change line 681 to:
That will make the initial center of the map the closest location – [0][2] is the first latitude and [0][3] is the first longitude.
Bjorn, you are the man!! That works perfectly. Thank you. Now, if only I could tweak further something else…
Here is the code with the change to the line you mentioned:
http://www.smefixit.co.uk/store/
if you type cornwall it will find the store in Ireland as it is technically the closet but there is a store in essex which I would ideally like this to be the first or selected by Country specific as I’m aiming to make this more of a distributor map which will not contain as many if it was stores.
Is there another simple code change please 🙂
Do you mean sorted by distance within the country or how would you want them sorted?
Hi Bjorn,
Sorted by distance within Country would work as generally I would only ever have one distributor per Country. Only in the USA I would deal by search within state you are located.
Many thanks as always Bjorn for your reply!
Would you be able to add the country code to the location data? I think that might be the best route to take. I would then recommend doing a reverse geocode on the user’s location (this function is already built in), get their country, and then filter the data by that country. I’ve actually been meaning to add email as an additional variable to work with and I could add country at the same time. I could probably push out an update with those things and some other minor tweaks this weekend.
Hi Bjorn,
I like your thinking 🙂 Yes this would work very well, top work man.
Thanks,
I just pushed an updated version to Github that includes the country variable.
Hi Bjorn,
Many thanks for your continued work on this project 🙂 – I have downloaded your latest changes and uploaded the new code to http://www.smefixit.co.uk/store/ but unless I have not turned on a piece a code (most likely) it decides to look over to Ireland for the “closest” and not within the UK which cornwall is. I’ve been looking at this all morning to make sure it wasn’t something my on my end.
Thanks for any pointers man
Yeah, you’re going to have to do some extra work to add the custom filter in. I provided the variable to work with but not the filter. I’ll get back with some code you can use in the next day or so.
One last comment, maybe : ) I have my JSON file validated and loaded. When I perform a search, it doesn’t display any results, however if I inspect the element I can see that it’s connecting to the Google API and is returning valid results. There is just nothing displaying on the page. Any idea on this? Thanks again in advance.
Make sure you have the coordinates in the data file and that the template files are loading. Put an alert or console.log right after the function locator(){ line on 111 – If they aren’t loading nothing will happen.
Great, thank you for all the help, much appreciated.
I got it working! Thank you for all of your help.
anyway to submit a zipcode to search on from another page?
(site.com/storelocator.php?zip=32792)
See above: https://www.bjornblog.com/web/jquery-store-locator-plugin#comment-15691
Hi Greg how you did it with submit a zipcode from another page
Thanks in advance
How can I display an email in the infowindow? I tried one of the answers listed above but it does not display the email.
What did you try and are you using all of the location attributes? Ex: Could you use hours2 or hours3?
It s working fine now, thanks.
Is it possible to add a store image on the infowindow?
Hi Bjorn,
I can’t locate a problem.
The script did work fine the first couple of weeks.
But now it doesn’t work in IE 8 or 9.
Firefox en Chrome no problems.
I can’t find the solution, are you able to help me?
http://bodiax.com/default.aspx?wsmt=wscontent&code=Info%20|%20Dealerlocator
Thanx,
Laura
A couple of things you could look into: It looks like there are a couple of XML issues. If I open the XML file in Firefox I get a Not Well Formed error on line 99. Also, it may not make a difference but I also get an error about superfish not being a function.
Solved,
stupid IE, some spaces where causing the problem :-/
Hi Bjorn,
How would I add an image in the xml file (image to be displayed on the infowindow)?
Here is how I am thinking of doing it: img=””
Would that be alright?
Thanks
G
I finally got the store images to be displayed in the info window.
Great work! Great plugin!
Thanks Bjorn
Hi Gotduss,
It would be great if you could share what you changed in case anyone else following may want the same thing.
Hi Gav,
Here is what I added to have an image displayed in the infowindow:
In the locations.xml file, after , I added
In the templates folder, in the infowindow-description.html, I added
You will also have to add the in the jquery.storelocator.js.
Cheers all,
G
Sorry, I should mention that you should be able to post code in the same format that’s described on: http://en.support.wordpress.com/code/posting-source-code/
My previous reply doesn’t seem to be displaying all the info, I write it again.
Here is what I added to have an image displayed in the infowindow:
In the locations.xml file, after hours3, I added img + name of the file
In the templates folder, in the infowindow-description.html, I added the html to display an image + path to the image + img
You will also have to add the img in the jquery.storelocator.js.
Cheers all,
G
Would anyone know how to style the infowindow?
Thanks
G
The only method I know of to change the infowindows is the InfoBubble library on this page (at the bottom of the list): https://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries
We have to change the name of the mapDiv to avoid conflict with another script. We made 3 changes and now we have no info window opening when clicking on map markers.
What other change from map to map2 is necessary?? We made the following 3 changes
‘mapDiv’: ‘map2’, in the js script
#map2 { float: left; width: 635px; height: 530px; } in the css file
on the index page
also changed divide on index.php to
That should be all you have to do. Are you sure there isn’t some kind of other conflict? Are you using Bootstrap by chance?
No we are not using bootstrap. Setting the variables back to map info window opens as it should. Only when we set them to back to map2, everything works except when clicking on the marker. The marker bounces, the listing divide jumps to the selected listing as expected but the info window does not open?
In addition to above, clicking on the listing in the list divide centers the marker as expected with the marker bouncing but not opening the info window..
Are you seeing any javascript errors (using Firebug or Chrome developer tools) or do you have a link to an example?
We set up a website using your downloaded code and only changed the three references to map as indicated. Changed the map id to #map2 in css file, Same change to js script: ‘mapDiv’: ‘map2’, and changed div in index.html to id=”map2″ – You can see the results on website pocketdex.com. Info window will not open??
http://pocketdex.com
Ok, it looks like I was able to replicate this issue. I’m looking into it.
I just pushed v1.4.6 up to Github, which fixes this infowindow problem. Thanks for pointing it out.
Would it be possible to tell us what the actual corrections were so that we can make them manually without downloading v1.4.6. If changes were made to only a few lines of the script we can simply make them rather then reconstruct the whole script??
We actually have mysql create the center starting point between locations and list locations within a selected radius input from center via json so we eliminated much of the original klm and modal code and replaced the hours variables in the script..
Thanks again for all your help — steve
Yes just 2 simple changes. You can see them on Github – changed 2 instances of settings.mapDiv to just ‘map’ in the create_infowindow function at the bottom.
I used your map at http://beginbright.sugoimarketing.com/
but getting some problem when i enter australian postcode that is 4220, then i geting a alert box that say location is far as 60 Miles. I think there is problem with fetching location from enter postcode, please have a look and getn me back as soon as possible.
Have you tried using region targeting as described in the instructions above?
I have managed to add on to Bjorn great work a powered by google auto places within the input address box, there may be a better way or less code changes but this works for my test http://www.smefixit.co.uk/store – start typing your place and google completes the rest.
To enable this part I changed this line in index.html
http://maps.google.com/maps/api/js?v=3.exp&sensor=false&libraries=places
and added:
It may be a hack but it does work for me. Big thanks to Bjorn for giving me the itch to use
Hi again,
I have the plugin working and it is awesome, thanks for putting your time into this. One issue I am trying to solve is when my locations are pulled up, they are all stacked on top of each other on the map. Basically it shows all the locations on the side bar, but on the map there is one marker. Any idea on this? If I click on get directions on one of the locations it is spot on, but visually on the map it is off. Again, any help is greatly appreciated. You can see the working example here http://www.cltampa.com/BoxLocator. Type in 33511 for an example.
-Dan
Did you set the latitude and longitude for each location? If I open your locations data file it looks like most of them are the same. Each location needs to be geocoded.
I did set the lat and long of each location, maybe I don’t have it linked correctly? I’ll look into this, thanks again.
When you say locations data file, is that my JSON file? Sorry, still very new at this stuff, but I appreciate all of the help.
Yes, in the JSON file. Just compare several of the lat/lng in the file and you’ll see that most of them are the same.
You are right, just opened it up. Well, hopefully this is my last question…what would you suggest for geo-coding 1600 locations? I used a free online geo-coder, but I guess it was not very accurate. Thanks, again.
I recently used http://www.gpsvisualizer.com/geocoder/ to geocode a couple of thousand locations. There is a limit per submission (I think it was like 1,000 – it will stop when the limit is hit and then you can export) but you can just paste in the rest when you reach the limit and combine the GPX files. I then used some PHP to get the lat/lngs back into the location data file. An easier solution might be http://batchgeo.com/, which I’ve heard good things about but it’s not free.
I used the one you recommended, worked great. I actually used it the first time as well, but I may have input them wrong or something, either way it is good now. I am working on turning this into a mobile version as well, has this been done already somewhere?
People have mentioned that they’ve used it for mobile in a couple of comments but I haven’t tried it for myself. I don’t see why it wouldn’t work though – you’d just want to have a different layout to accommodate smaller screen sizes.
Hey Bjorn,
could you maybe help with this Problem. I need to display one “premium” location first regardless of distance. There is already two types of Locations with different styles. After the first one it should sort by distance only.
You will receive a small donation when im through with this project 😉
Others have also asked for this and I actually have to do it for another project… so, it’s coming soon. It looks like I have a solution sorted out – I’ll try to get the plugin updated by the end of the weekend.
let me know if I can help you with something or if youre stuck at some point. Maybe I can work out a solution from that point.
It really would be nice to have this worked out on monday since I have an appointment with my Client.
Thanks, I have a working solution in the other project I was working on (basically a fork of this plugin with several modifications). I just need to copy it over and maybe do a little optimization at this point.
thank you sounds good. I would be happy with just the code for that specific option to add to the existing js since I have a modified Version myself I wouldnt want to change much.
I have added a featuredLocations option in 1.4.7, which I just pushed to Github. You can see the changes in my commit.
Thank you very much for your effort this is how far I got the logic of it in my mind. However I would need to display just one location of the featuredset on top before the regular locationset and not the normal set is loaded without the location used in the featuredset. So that makes it somewhat more complicated I guess.
I will try to figure this out unless you already have an idea on how to do this and are kind enough to post your thoughts.
Hi Bjorn,
Did you kindly have any code to filter the country region tag as I’ve been scratching my head about this and haven’t managed to figure this out myself.
Sorry, looks like our original thread won’t allow any more replies.
Thanks,
Oh, yeah. I almost had it done – I’ll post it tomorrow evening.
Hey Gav,
Try the following:
In the ReverseGeocode function after the result.address line on 181 add:
In the begin_mapping function change mapping(….. on line 263 to:
Add the following after the begin_mapping function, should be after 272:
In the mapping function around line 326 add userCountry as the last paramater:
Then, assuming you’re using XML without the max distance option, look for the //Process XML line around 456. Go down a bit and in the else{ around line 487 change it to the following so there’s a new if inside the else:
Hi Bjorn,
Thank you for this Bjorn, I have made the changes but when looking at the developer panel on IE9 I see: (example with changes http://www.smefixit.co.uk/store/)
Should this line:
be:
Or I am wondering if the variable userCountry needs to be added somewhere at the top?
Thanks again Bjorn!
userCountry is defined as a parameter of the mapping function, which you have. You have the if(country === in the wrong spot. Here’s a better view – it needs to be in the //Process XML loop:
Hi Bjorn,
Thanks, it’s funny I had that code in that area but then for some reason I moved it down further. Sorry but it still fails with:
I did start over to make sure I didn’t mess anything up and I also did a google search to see if it was something obvious I missed but think maybe it is something deeper.
Sorry to trouble you further 🙂
Ah, ok – I was hoping country would always be the 6th element returned but it looks like that’s not the case. For the first step change it to:
Also, I noticed that if you do a reverse geocode on Essex, for example, it returns the country code GB and not UK. So, you’ll want to change that in the XML file.
Bjorn this is great this works well once but if I search say cornwall it brings up the expected result but then if you search again with “turvey donabate” it finds correct on the map but the left side panel shows the wrong information and the code error in the IE9 Web Console:
1
2
SCRIPT5007: Unable to get value of the property ‘2’: object is null or undefined
jquery.storelocator.js, line 725 character 17
It also fails to search any longer until you refresh the web page. So nearly there 🙂 I can’t thank you enough!
Ah, ok a quick fix is to move the i++ within the if(country === userCountry…:
The approach I was taking for the other filters was that a location would be added on each iteration of the loop but with these more advanced filters that’s not always the case (the first location would be skipped in the XML file in your example with the turvey donabate search. I suppose I should re-work the way that works in the plugin but the above should be fine in your case if you’re not planning on using the maximum distance option.
That fixed it Bjorn…Thank you so much again for your replies the map works very well with these extra tweaks 🙂 I wasn’t concerned with the distance alert due to making this more of a distribution finder than store.
There is a small bug but I can live with it but for other people following if you enter an address (i.e new york) where no store exists the following error will appear:
I would expect a unable to find store error but due to not using the maxdistance code this gives a code error.
Heh, the count is just throwing lots of things off. I didn’t develop it thinking of completely filtering locations out – just re-ordering them. You could change:
to
Under the //Check closest marker comment. You’d want to leave the distance alert setting on though and it looks like you commented that out.
Thanks Bjorn, this worked but I’m going to look in to how I can tweak your code to say something like…No distributor located in this area, if you would like…” so on, or I may do away with that part and leave it like it is as it works well 🙂
Great to hear, that will probably be just in time. Thanks in advance!
I used store locator at http://beginbright.sugoimarketing.com/ and it working fine, but my clients need to change marker when he click on sidebar list item/map marker then marker change to green color.
This is trickier than you might think. The easiest solution I can give you changes the selected marker to a green dot but resetting all the markers on subsequent clicks and carrying over the letter might take quite a bit more work. After:
You could add:
Everybody is good,why I do not run download demo
You need to run it on a web server. It won’t run out of a folder.
Thank you very much! I have solved
I have one script
http://www.websolutions.pt/midas_mobile2/oficinas_proximas.asp
but for any reason, sorting is not working and i can’t add distance on it.
I’m thinking use what i have at
http://websolutions.pt/localizador/ but i only want locations, don’t need map.
Thanks
I tried
but there is any other solution ?
With your code i don’t need any google api maps v2 api, right ?
in line
sensor must be false or true ? i’m sorting locations by geolocation.
Thanks
Yes, the origin location needs to be Geocoded with the Google API or something else. This plugin uses the Google Maps v3 API. You actually can’t use the Google API without showing a map: https://developers.google.com/maps/documentation/geocoding/#Limits
If you don’t want a map I think it’s alright to use the Bing API. I had to do it for one project – you just need to replace the code in the GoogleGeocode function with the following (note you have to register with Bing and provide your own key below):
Hi Bjorn. As many have said before, kudos on such an awesome plugin! I am hoping that you can help me out with a couple questions:
1. Do you have a functional example of the category usage that I can reference? I have been trying to work through the revisions that you suggested to Devin, but it does not seem to be working for me. Every time I try it locks up all JS, I was getting an error in particular saying that “selectedCat” was not defined…
2. For some reason I always get the no listings within “undefined” range when I load that page. Clearly I must be doing something wrong.
I have posted the code here: Demo. Any help you can offer is most appreciated!
Thanks!
1) I don’t think I kept the example that I did to answer Devin’s question. I would diagnose this by going back and making sure selectedCat is getting set and correctly passed down to the right spot. Use console.log with Firebug or Chrome developer tools to make sure you’re getting the correct value and make sure it’s being passed into the main mapping function.
2) I’m looking into this and it could be a bug. It looks like the problem is happening because both a default location and max distance are true. It’s hard to test for all the option combinations.
Thanks for the reply Bjorn! I as able to get rid of the pop up and will continue to tinker with the Category code. Thanks again for your time.
Is there an easy way to show all locations in the map but return a limited number of search results in the text listing?
yes there is a very easy way to do this just set overflow to hidden and clip at the desired list length.
The challenge is that my map contains hundreds or thousands of points. I’d like to show them all on the map but avoid having to load all of that extra data as a list.
You should be able to replace the .each() loop that beings under the “//Create the links that focus on the related marker” comment with a regular for loop (keep the line directly beneath the comment though). I think that would work. Ex:
It is possible to display more than 26 Markers in the clickable List of the left Side of the Map? I have 60 Markers and it shows only 26. I have try to change the Numbers of max. Markers, but it takes no effect.
Yes, you should use the storeLimit option and the easiest way to tell that it is working is it will switch over from alpha characters to numbers in the red boxes in the location list. How are you setting the option?
If anybody wonders how to return only one featured location on top of the List and after that a list sorted by distance… This is how I did it: Basically created two new functions with slight modifications of $grep and put them into the jquery 1.9.1.js (If anybody knows how to get it into the store locator file let me know since that strangely didnt work for me):
grep_once: function( elems, callback, inv ) {
var retVal,
ret = [],
i = 0,
length = elems.length;
inv = !!inv;
// Go through the array, only saving the items
// that pass the validator function
retVal = !!callback( elems[ i ], i );
if ( inv !== retVal ) {
ret.push( elems[ i ] );
}
return ret;
},
grep_nofirst: function( elems, callback, inv ) {
var retVal,
ret = [],
i = 1,
length = elems.length;
inv = !!inv;
// Go through the array, only saving the items
// that pass the validator function
for ( ; i < length; i++ ) {
retVal = !!callback( elems[ i ], i );
if ( inv !== retVal ) {
ret.push( elems[ i ] );
}
}
return ret;
},
after that change the first $.grep to $.grep_once and the second to $.grep_nofirst
ok that doesnt work correctly posted a little to quick there. I will solve it now though and post it again if requested
Is it possible to have a second location name-based search box in addition to the address/zip search box that controls the same map and listings that appear?
Well, it would probably be possible but it would take some work. This is not currently built in.
I’m trying to implement your plugin on my WordPress site and I’m running into a little difficulty. For some reason the script is not picking up the template files. I adjusted the file paths in store-locator.js, enqueued the script in my functions.php file and copied the css to my main style.css file.
Any idea what might be going on here? I’m stumped.
Have you tried checking the paths in Firebug or Chrome developer tools? You should be able to get where it’s looking for them from either tool.
Hi Bjorn,
I wondered if this had been tested for use on mobile websites? EG, Android/iOS/Windows Phone?
This looks like a really handy plugin, just wanted to check first.
Keep up the excellent work!
Hello,
Yes, I haven’t done it myself yet but I have seen it working on mobile devices. I’ll probably be adding a mobile example at some point in the near future.
Hi,
I’m new with using store locator scripts. How do you go about finding the longitude and latitude coordinates for the locations in the XML file?
Thanks!
If you have a lot of locations you’ll want to look at some bulk geocoding services such as http://www.gpsvisualizer.com/geocoder/ or http://batchgeo.com/. If you don’t have a lot you can use the geocode.html file included with the plugin files or something like http://geocoder.us/
Hi, Is it possible to access the map after its drawn? To add overlays for example?
Thanks,
Amir
Hello,Bjorn.
Back in February, you made an example of how to change marker color according to different type by answering James’s question. I tried to do this using your latest plug-in but no luck.
In V.1.4.8(the latest ver.), I added “ ‘type’: $(this).attr(‘type’)” instead of “var type = $(this).attr(‘type’);”
Then, a few lines after where the locationset arrays are defined, (since you’ve changed this), I didn’t add anything.
Then, I added “locationset[y][‘type’]” where you instructed to place “locationset[y][14]”
Then, I added type to createMarker function as instructed. i.e. “function createMarker(point, name, address, letter, type) {“
Lastly, Added “if (type=== “Bank”){ var pinColorOverride = “6991fd”;} else{ var pinColorOverride = “fe7569”;}”
In Firebug console, I got an error with variable undefined with “if (type=== “Bank”){“ so I changed this with “if(locationData[‘type’]=== ‘Bank’){“. Now, Everything is working except markers. Markers are invisible and I get errors “NetworkError: 400 Bad Request – http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=D|undefined|000000″ in the firebug.
Could you show me how I can change the marker depending on type?
Thank you,
You actually don’t need to worry about creating the type variable anymore as I’ve included the category variable in newer versions. You’ll need to make sure you have the category set in your XML data file and then instead of following the instructions I gave James above, you can do:
On 693:
On 752:
Directly after that (example):
Then a couple of lines down change the var pinImage = line to:
Thanks, Bjorn! Works now!!
Hey Jean I am trying to exactly same thing, but no luck. Can you tell me where i could be wrong. In my case i do see the marker pins , but all have same default color. I followed exactly same code snippedt as ya had. Can ya help me ASAP!
Hi,
Great job, this piece of code!
I’ve got it working, but I have one small problem:
How do i refresh my locations ? I’ve changed some bits of information in the kml file (in the description field actually), but it’s still the old text from the initial kml file that is being displayed for that specific location.
I guess Google is caching the information, but am not sure how ?
Hi,
In my previous message, I wrote that the changes I made in the locations file weren’t reflected on the website.
Now that I’m testing the same page at home, I notice that the markers aren’t even showing on the map.
Would you mind having a look here:
http://kbase-venice.unit4.com/dev/verdeler/
Enter for instance ‘brugge’
It correctly displays the city, but fails to show the relevant dealers on the map.
The kml file should be ok, it loaded fine in google earth and showed all locations.
Any ideas ?
Thanks,
Tom
Hi,
I finally solved all problems!
first, after opening the kml file in an editor, I noticed it didn’t contain the geocoding after all. Opening the file in google earth was not a good test, as Google Earth probably did the geocoding on the fly.
With respect to the caching issue, I solved it by disabling caching for that page on our IIS server !
Thanks again for such a great plugin !
Hi,
Any idea why changing the url (I just moved it one level up) would result in this error message on some of our website visitor’s browsers (when I test it myself, it’s ok?)
HTTP Error 405: The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.
Sorry for the delay. Are you using a static HTML page to display the locator? If yes you may want to check out the following answer on Stack Overflow. Not sure why it would only be happening to some people though.
Hi bjorn,
Its really very good code.But when i downloaded and check it from my machine,
There is nothing displaying after clicking the submit button.
I am sure that locations.xml is in the directory.
I am sorry in asking this sily question bcause i am pretty new to this, it would be appreciated much if you help me.
It will not run out of a local folder. Put it on a local or remote web server.
It works great !!! thanks a lot !! I have a question that whether v could modify this for a ipad app ! when it tilted in landscape the side bar should be shown and when it is tilted to potrait the side bar should not be showed !is this possible ??
And also i would like u to explain how to the places from my database which script i should modify ??
Thank you !
Hello Bjorn,
I was wondering, can I use this plugin without the sidebar feature and without the database? I am planning on using this plugin on a mobile web app I’m designing for my Thesis and all I need it to do is find local farms and local farmers markets. Can you help me out with this?
You can definitely use this without the sidebar. Can you clarify your database question? The primary examples above use an XML or KML file (the JSON file is database generated but it doesn’t have to be). How are you planning on getting the correct data?
hi Bjorn,
would you mind to re-create this great plugin for angularjs, please?
I haven’t done anything with Angular yet but it might be a possibility at some point in the future.
Hi Bjorn,
Thanks for the great work.
I’m having a problem here where instead of having users keying into the text box, I’d prefer to create a drop down to filter by countries instead – but I’m not sure how to do that?
So you’d want it to just show all the locations in the country that is chosen?
Yeah, something like this:
http://imageshack.us/photo/my-images/90/i2no.jpg/
Hi Bjorn,
Your new featuredLocations works great! I’d like to add an image like a star next to the featured location in the listing, and change the marker to a different color if possible. Can you please point me in the right direction?
Thank you so much!
Sorry for the delay. Yes, you can do that pretty easily. In your location-list-description.html template use the Handlebar helpers. Example:
For the marker switch, you just need to pass the featured variable down to the createMarker function. In the for loop around 690 change:
to:
Then down in createMarker function around line 752 you could change the beginning to look something like this:
Changing the pin color works great, but for some reason, the {{#if featured}} condition wouldn’t work for me – the star displays for all addresses. So I got around it by adding a featuredImage parameter, and set it to either a star or blank image.
Thank you for this great plugin!
Hi!
I would like to do the same, but I don´t know how to stand out a marker (for example changing the icon)
I load 99 places in my map.
And what about stand out the marker on the list? Is it posible?
Thank you
Hi Bjorn,
It’s a fantastic plugin!
following your suggestions above to make a filter, I did some alterations in the code to accommodate a couple of filters:
1) function begin_mapping(distance)
{
//Get the user input and use it
var userinput = $(‘#’ + settings.inputID).val();
var selectedCategory = $(‘#category’).val(); // *** OR ****
var checkedCategory =$(“input:checked”).val();
var checkedWheelchair =$(“input:checked”).val();
2) if userinput = “”
…..
mapping(olat, olng, userinput, distance, checkedWheelchair);
3) function mapping(orig_lat, orig_lng, origin, maxDistance, checkedWheel)
and finally
if(settings.maxDistance === true && firstRun !== true){
if((distance < maxDistance) && (wheelchair === checkedWheel)){
locationset[i] = [distance, name, lat, lng, address, address2, city, state, postal, phone, web, hours1, hours2, hours3, category, wheelchair, audio];
Once these changes are made, the new filters work great. This only problem: user needs to actually check all options: miles + filter 1 + …..
Do you have a suggestion on how to push markers if user only checks the miles and nothing else? Or miles and (in my case) wheelchair but diresgard the category (I had put restaurant, bar, golf, but it does not matter, above just with wheelchair).
If I use OR, it does not produce the right options: For instance = New York AND bar AND wheelchair. First, everything in NY, than bar, finally wheelchair. But not bar in Chicago (this would happen with OR.
Thank you so so much for your time!
hi Bjorn,
I may need some assistance regarding database and XML syncing, if that’s even possible but first I just like to say that you’re plugin is a lifesaver and I’m very grateful! No WordPress plugin could provide me the functionality and flexibility so I explored your plugin.
Thanks to your documentation and the thread here I was able to create a form on a separate page and load the search results on another. See http://medifastdev.neon76.com/find-a-center/ and try ‘San Diego, CA’ in the search field.
As mentioned, I’m using a static xml file for all the locations. What I want to find out is how to pull the data from WP database into the XML so I won’t have to manually update it when the client updates the locations.
Incidentally the locations are a custom post type.
They have an archive WP template – http://medifastdev.neon76.com/location/northern-california/ and
a single post template – http://medifastdev.neon76.com/center/citrus-heights/.
Thanks so much!
Bjorn,
The coding which u have provided for json is throwing an error .
while($r = mysql_fetch_assoc($results))
I am getting error on this line please revise your code and give me solution. Thank you.
Hi,Bjorn
I am trying to show (a) featured store(s) only within distanceAleart or city instead of show the store(s) no matter what.
How do I change code under //Featured Locations filtering?
if((settings.featuredLocations === true)&&(locationset[0][‘distance’] < settings.distanceAlert)){
I am a little slow so would be great if you could shed a light on me.
Thank you,
I’d probably just use the maxDistance option and hard code the maximum distance instead of giving people a choice.
Thanks for the hint, Bjorn!
Hi Bjorn, I’m trying to incorporate your plugin into my webpage but I’m having trouble. I’ve copy and pasted your code in and uploaded the xml file just to see if I can get it to work. My page displays everything up to the entry form (where it says Enter Address or ZIP) just fine, but when I actually enter in a ZIP code and hit enter the page refreshes and neither the maps nor the locations show up.
How can i resolve that issue
Make sure you’ve uploaded the template files and set the paths correctly and have followed the usage steps 1-6 above.
Hi Bjorn!!
Nice code.
I just wanted to know… what about loading thounsand of points? I have a website with more than 10000 points. If iload all of them with your code, it is going to be too hard, or not?
Hi Bjorn,
I´ve just tried
http://placesforlove.com/pruebas/stores/
It seems it has to load all the KML (10000 points, about 6 seconds)
In a mobile device the speed is very slow..
What about the JSON? Do you think it will have better perfomance?
Do you know how to put a loading gif after pressing the button of SUBMIT until the map is loaded?
Thankyou!!!
Well, yes it has to calculate all the distances to each location in order to show the closest ones. 10,000 is quite a lot – my recommendation would be to try to break it down further if possible by some kind of regions. Can you break it down by country or state/province? There is a loading option above that if you set to true will show a loading gif next to the input box. Some people have indicated that KML is slower than JSON but I’m not really sure myself – probably worth testing. Also, I’d put it up on a cloud hosting service or CDN if you can.
(Sorry, I wrote a reply post but I don´t know if it has been published…)
Hi Bjorn. I think I have the solution but I have another problem..
The only thing I can do is load the markers near the searched address.
I have a PHP script wich connects to the database and search for them
For example: http://lovingplaces.com/kml_lovingplaces_variable.php?latitud=43&longitud=-2&distancia=100 It retrieves a KML list of points near to that position.
So… I just have to replace
‘dataLocation’: ‘locations.kml’,
with
‘dataLocation’: ‘http://lovingplaces.com/kml_lovingplaces_variable.php?latitud=’+milatitud+’&longitud=’+milongitud+’&distancia=100’,
The big problem is that the longitude and latitude is undefined at the moment of the settings…
I need to know the lat an lng befeore the setting to set the variables.
Any idea…?
Thank you
I’m not sure I understand what you mean. I opened the link you included and I see coordinates that look like lat/lng to me.
Hi Bjorn!
It´s easy. Your script shows all the markers because load all the markers loading locations.kml
What I want is just load the markers near to a certain latitude and longitude. I do it with a PHP script, I pass to the script the coordinates and it returns the markers. For example: http://lovingplaces.com/kml_lovingplaces_variable.php?latitud=43&longitud=-2&distancia=100 It retrieves a KML list of points near to that position.
So… if I replace
‘dataLocation’: ‘locations.kml’,
with
‘dataLocation’: ‘http://lovingplaces.com/kml_lovingplaces_variable.php?latitud=’+milatitud+’&longitud=’+milongitud+’&distancia=100′,
I will only load the markers near that position!
PROBLEM: When the settings variables are defined (at the beginig of your script) it doesn´t know already the coordinates, they are obtained lines above with the Geocode… How can I know the coordinates before set the options (the settings)?? Or how can we convert the submitted address to coordinates before set the options??
With this solution your script will be usefull also for reading huge database!
Thank you very much.
Josean
I solved it!!
INTERESTING FOR EVERYONE WHO WANTS TO LOAD POINTS FROM A HUGE DATABASE:
Remove from settings
‘dataLocation’: ‘locations.xml’,
Search for:
url: settings.dataLocation + (settings.dataType === ‘jsonp’ ? (settings.dataLocation.match(/\?/) ? ‘&’ : ‘?’) + ‘callback=?’ : ”),
And change it for a calling to PHP wich will make a search in to a database WITHOUT LOADING ALL THE POINTS
url: ‘searchdatabase.php?latitud=’+orig_lat+’&longitud=’+orig_lng+’&distancia=1000000’ + (settings.dataType === ‘jsonp’ ? (midataLocation.match(/\?/) ? ‘&’ : ‘?’) + ‘callback=?’ : ”),
Dear Björn,
great script. But do you think there is a way to grab the store informations directly from an SQL Database without going via the location.xml?
Best Regards
litreb
Yes, set up a database query and output JSON. Please see the JSON section in the original post above and the JSON example.
Hi Bjorn,
we have a secure website (https).
I would like to change the script so that it is secure.
Do you know where I have to adjust this to make it happen?
greetings,
Laura
You’d want to the includes/calls. Google Maps supports SSL so you can just add the https for Google Maps. Hosted jQuery versions should also work, otherwise you can include a local copy. In the plugin there are 3 http calls to chart.apis.google.com and then 1 to maps.google.com. If you just search for http:// you should find them. I don’t think you would need to worry about the replace(“http://”,””). I should update this plugin so that SSL support is built in.
Hi Bjorn,
This is the plugin I’ve been looking for!
I have trouble including it into wordpress tho… I don’t know how to include it properly in the function file I tried to enqueue and register but it didn’t seem to work for me I think I did it wrong… Here is my code :
http://jsfiddle.net/vTkV4/
Can someone assist me or redirect me to a tutorial, or just gives me the proper code to put into the functions.php ?
Thanks!
You’re enquing too many files. The geocode JS file is just there so you can geocode a few points with the geocode.html file if it’s convenient (don’t include that). You’re also including minified files and the regular files. Ex: jquery.storelocator.js and jquery.storelocator.min.js are the same but the .min is minified.
Dear Bjorn,
Everything working fine.but I am facing the problem with loading map,it’s loading but its look like blurred map.could you please help me to solve this issue.
http://supertool.tdtomdavies.com:8080/wwwtd/storelocator.aspx
Hello Bjorn!
I have three store categories (Retail, Wholesale, and Both) in xml, and I’d like to display selected store category accordingly when desired category is selected using select box. I am using featured =”true” for some of stores in xml. Those featured stores will be shown within 70 miles maxdistance so that a featured store in New York will not be shown when I enter Miami in the search box.
I followed your steps shown on April 15, 2013 at 12:07 am. exactly. When I search any cities or zip codes, I get a distanceErrorAlert popup messsage. If I remove “(category === selectedCat)”,the pages loads fine but category box becomes useless. There is no error in firebug. What did I do wrong? Any help would greatly be appreciated.
In HTML,
wholesale and Retail
wholesale
retail
//Create the array
if(settings.maxDistance === true && firstRun !== true){
if((locationData[‘distance’] < maxDistance) && (category === selectedCat)){
locationset[i] = locationData;
}
Just a quick question, does this use any Google Maps API calls at all? no one else has asked and I’m a bit confused because I’m putting this on a high traffic site so I don’t want it to go over the limit. Or rather how can I use an API key with this script.
Thanks!
Yes, the only things you should have to worry about would be map loads and geocoding. For the standard version, the limit for Map loads is 25,000 per day and for geocoding it’s 2,500 requests per day and 1 per second. This plugin only geocode’s the user’s input and not the locations to avoid issues with the geocoding request limits. You can easily add an API key by just adding a key query string parameter to the main Google Maps API call: ?key=API_KEY
Full example:
https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=false
Hi,
I have used your store location and it works really well, do we have the option of having different markers/points on the map for different types of businesses e.g. one for store and one for head office.
hopefully someone can help
many thanks
Amar
Hi,
looove your plugin and it works great, but I need one thing.
My client needs to have address input box on a home page and send it with GET to a page where your code is.
I managed to pick up address and put it in a input box on that page but when i trigger submit button it keeps going on and on and on….
Where I need to put return false; ?
Or any other suggestion?
Thank you,
Iva
I’d recommend using the modal option but if you absolutely have to I have an example explained in the following comment above that will get you started: https://www.bjornblog.com/web/jquery-store-locator-plugin#comment-15691
Hi Bjorn,
I tried your example but it doesn´t work…
What doesn’t work? You have to have the browser console open in order to understand how the example linked above works. It’s not really a fully working example, just something to get you started with passing the input from one page to another.
Ups…. sorry.
I´ll try it.
Hi,
I have php that send location and i am picking it up with php, so that part is ok. I have changed your code a bit, closed function, little fix:
var get_location = '';
if(get_location !== ""){
$("#address").val(get_location);
//var g = new GoogleGeocode();
var g = new google.maps.Geocoder();
var address = get_location;
g.geocode(address, function(data) {
if(data !== null) {
olat = data.latitude;
olng = data.longitude;
mapping(olat, olng, userinput, distance);
} else {
/*Unable to geocode*/
alert(settings.addressErrorAlert);
}
});
}
else{
$(document).on('submit.'+prefix, '#' + settings.formID, function(e){
get_form_values(e);
});
}
But now I get error
Uncaught ReferenceError: GoogleGeocode is not defined
Iva
sorry, this is code where i tried to comment that line and use google.maps.Geocoder()…didn’t worked
code is like this:
var get_location = ”;
if(get_location !== “”){
$(“#address”).val(get_location);
var g = new GoogleGeocode();
var address = get_location;
g.geocode(address, function(data) {
if(data !== null) {
olat = data.latitude;
olng = data.longitude;
mapping(olat, olng, userinput, distance);
} else {
/*Unable to geocode*/
alert(settings.addressErrorAlert);
}
});
}
else{
$(document).on(‘submit.’+prefix, ‘#user-location’, function(e){
get_form_values(e);
});
}
WORKING :))))
forget previous posts, I could delete them if I can.
Only problem was that ‘distance’ was not recognised, it was complaining that is undefined, instead of var I put my max distance value and it worked.
I added code to jquery.storelocator.js after if statement for
//ASP.net or regular submission?
Thank you,
Iva
Hi Iva,
I tried to pass a variable parametre in order to load the points of that location.
I pasted your code after //ASP.net or regular submission?
It seems to work, because it puts the value of the variable I passed in the INPUT text, but it does´nt make the search and draw the map!
Any idea…?
Hi there. Cool plugin. When using KML is there any way to bypass the custom markers in the script and just use image urls in the KML file: “url”… ? Thanks.
Sorry, this is something that’s on my list but I haven’t gotten to it yet. I haven’t looked into it yet so I’m not really sure at this point.
Hi Bjorn,
Firstly great work!
I was just wondering if it was possible when submitted, if the map could go straight to the nearest location instead of the inserted address?
Thanks
Chris
If you don’t care much about the zooming, the easiest way to do this is to use the zoomLevel setting and set it to 0. That will automatically center and zoom based on the results.
Hi bjorn,
Thanks for your plugin.
I just want location list to be in alphabetical order, can you suggest me how to do it.
Yeah, you could either add a new function or edit the sort_numerically function. If you wanted to do the latter, you should be able to do this:
Search for the “Distance sorting function” comment – around line 490. Within the sort_numerically function change the return line to:
I didn’t test it but that should work.
Bjorn – great job on this! Quick question, I have a rather small list of locations in my .xml file – is there a way using your script to just print them in the list to the page – sorted by “city”? I have everything else such as the zipcode lookup and autogeocode versions running – but I would like to have another page which simply lists them all out.
Thanks!!
Without the map? It’s actually against the Google Maps API terms to use the API without showing a map. However, it doesn’t seem to be against Bing’s API (at least as far as I can tell) and I’ve actually done a custom implementation with it for a company that just has a listing with paging. I might make a fork or something on Github and post it up.
Great plugin! I very much appreciate your hard work!
I am trying to include a filter to narrow down the search results by category (day). I tried to incorporate the suggestions in the April 5, 2013 thread above started by Devin but I think I failed. The search results now only return one location (the closest location) and are not filtering by category regardless of what day I select. How can I go about returning results based on the category (day selected). Here is my search form:
http://www.ecobuzzla.com/search/maxdistance-example.html
Thank you!
To start off, it doesn’t look like you’re getting the value of the selected day. It looks like you’re using the ID day so the first bit of code you’d need to add would look like:
Hi, Great plugin! Is working great except in IE8 for some reason, the markers are not showing properly.
When I click the entry in the list, the animation of the marker plays and then disappears. When looking for the markers, they don’t appear. It only happens in IE8 and I’m not sure why.
Did you change any of the code? I just tried the demos with a virtual machine with IE8 and it was working as expected. How are you testing it?
I must be doing something wrong, but the map isn’t displaying. I’m testing it out with the files downloaded from GitHub (update.flyingskull.net/store-locator.php). Can you see what’s going on?
Yes, the templates aren’t being loaded. Did you upload them?
Hi,Bjorn.
I have Retail, Wholesale, and Special in the ‘category’ in xml.
What I’d like to do is to show those locations using select option or checkbox to display desired category within maximum distance of, let’s say, 60 miles. I have select options (e.g. All, Special, Retail, Wholesale).
I placed,
If ((locationData[‘distance’] < maxDistance)&&(locationData['category'] === selectedCat)){
locationset[i] = locationData;}
The above displays desired locations by selecting category from drop down menu. But it doesn’t display all of the locations (Special, Retail and Wholesale) at once (by selecting All) and get an error popup message "Unfortunately, our closest locations is more than 60 miles."
If I remove the above, and place ‘(locationData['category']=== '' || locationData['category']=== 'Special' || locationData['category'] === 'Wholesale' || locationData['category'] === 'Retail')’, I can display all of the categories at once but unable to display results by selecting any category from option.
How can I display any desired category or all the categories?
Thanks,
Quick question: Is it possible to show a map without any markers on initial page load?
where did you put this code or how you did it
i need help please
Thanks
Quick question. Can you set to display just the nearest 5 dealers let’s say? No max distance, just the nearest x amount of dealers.
Thanks!
Hi,
Managed to set it to use MySql database easy enough 🙂
I know you have a lot of questions to answer on here but thought I’d try my luck 🙂
When the map is loaded, How would I get it to display only the markers with the bounds? And then auto refresh when zooming out?
Thanks!
Hi,
Its working very good for me. but the name is not displaying in the sidebar. Instead of displaying the store name. It is just displaying ,(comma) i am using mysql and json. please help me in sorting this out.
I get all my locations with locations.php But I get this message. Unfortunately, our closest location is more than 15 miles. I change the following lines in each file. map does not show up.
Please Help me
Thanks
jquery.storelocator.js
‘distanceAlert’: 60,
‘dataType’: ‘xml’,
‘dataLocation’: ‘locations.php’,
‘listColor1’: ‘ffffff’,
jquery.storelocator.min.js
dataLocation:”locations.php”
locations.php
PHP create XML file from Mysql locations table.
file name: locations.php
Hello,
My question is really stupid and basic but I’m completely unfamiliar with the subject. I need to provide quickly solution for store location. I downloaded your folder from Github but when I try to run one of included examples I don’t get any map at all. Just a form to fill in and after there is no map appearing ?? What did I missed ?
Thank you in advance
You need to run it on a local or remote web server. It will not work out of just a directory.
Php update MySQL locations table by adding the latitude and longitude for each address
here is the zip file link
http://bnetdesign.com/downloads/updateMySQL-locations.zip
Hi,
Thanks for this great plugin, it works great. However, before using it in my company I am going to see if it is possible to feed it directly from a java servlet with json data in a way that the search is performed on the database (using the distance formula you mentioned). The main reason is that if I create and xml with all my store data (over 3,000 third-party stores), anyone using the locator will be able to get this file from his/her browser’s cache on the blink of an eye. I would get killed by the CEO!
Hi again,
I tried the servlet thing, and it works like a charm. Now the database does the filtering, and only the nearby stores are passed to the store locator. That way it is more secure for us and also more efficient. And the store locator gets de JSON data with no problems. Thanks for the great design, Bjorn!
Is it possible to display a message somewhere after they have searched, or the geo locator has found them, that says:
“20 Stores were found within 30 miles of you location”
Hi Bjorn,
This is a fantastic add on. I; having some issues getting it to work with the Big Commerce platform. The URL is http://www.kiwicigusa.com/store-locator-kiwicig
Any help you can provide is sooo appreciated.
Joanne
The first issue I’m seeing is that two different versions of jQuery are being included. The plugin should work with 1.7+, so try without including the 1.10.1 (1.7.2 is already there).
Hi Bjorn!
I went ahead and removed the 1.10.1 reference…. I didn’t see any difference. I also tried wrapping the function in a $(document).ready in case there were timing issues with the way BC renders the page. No effect.
Hello everybody!
I just finished my website using Bjorn plugin.
You can visit it here:
http://placesforlove.com
It loads place for make love in the world. In Spain we call them “picaderos”
Te loading is dinamic depending of the given address.
What do you think about it?
Hello,
Currently using your jquery plugin on an internally hosted website, we will be going live with it shortly. Running into a few problems. Auto-geocoding of user location, works fine, searching for zip codes works fine (sometimes), but I sometimes get the following error:
Geocode was not successful for the following reason: ERROR
Typically this happens when trying to search for an overseas locations such as Paris, France or just Paris or just France.
This also happens randomly when searching for zip codes, state names or cities.
My main site runs on ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js (don’t know if this is causing any issues).
We’re also using: animatedcollapse.js and jqFancyTransitions.1.8.min.js
My locations.xml file also contains about 971+ locations (we are a manufacturer using this script as a vendor/dealer locator)
Any assistance or insight would be appreciated. My fear is that is is conflicting with a different script on the page, as running the index.html file directly off our server never has issues, but running the file imbedded into our dynamic site causes problems.
Resolved issue by causing store locator to appear in inframe lightbox pop out. Looks slick and works well.
Hi, Bjorn….
Any thoughts on my BigCommerce integration issues? I removed the second jQuery library reference, but it had no effect.
Thank you!
Joanne
Bjorn…was able to solve the issue.
For other BigCommerce users, beware of the WSYWIG editor. I entered the store locator code within the content area of a standard web page. For some reason, the WSYWIG editor caused some type of issue. When I entered the code without the WSYWIG editor turned on, the store locator code worked perfectly. To get around my client accidentally messing up the code, I entered the store locator code within a panel and then referenced the panel within the content area of the web page.
Thanks, Bjorn, for providing a very cool piece of functionality. One of the best (if not the best) out there!
Joanne
Hello mister, how to change address and post code search replacing by event klick on the map as origin. please reply to my email mister 🙂 Thank