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.
I’m showing only the 5 closest stores and have been able to add a button to show 10 or 20 stores but is it possible to add a button to “show next 5 stores” and have it replace the currently displayed stores with the next 5 in the array? If so, what code would I use?
Anybody have a solution for this?
Hey Bjorn thanks for the hard work for the script, i have been having trouble trying to implement it with my coldfusion server side would love if you could take a quick look and let me know if you find anything that could get it to work for me! http://www.cheapcarpetmelbourne.com.au/index.cfm/5/storelocations
Cheers!
It doesn’t look like it’s there anymore. If you have a test page I’ll take a look but I have no experience with Coldfusion.
Hi there again,
Thanks for all the hard work on this excellent piece of code … was wondering if anyone has a way of easily adding a pin for the entered search location – preferably with a different coloured pin.
Useful when you start to scroll the map around.
Hello it’s pretty simple:
Check out my code and the line I’ve added, you’ll notice you have to declare the var “image” with the link to the icon:
//Ferme si la touche Echap est appuy
//Ferme si la touche Echap est appuyee
$(document).keyup(function(e) {
if (e.keyCode == 27) {
$(‘#overlay’).hide();
}
});
}
var map = new google.maps.Map(document.getElementById(settings.mapDiv), myOptions);
var image = ‘/css/img/marker.png’; // <—– CHANGE THE ICON PATH HERE!
var marker = new google.maps.Marker({
map: map,
icon: image, // <– DON'T FORGET TO ADD THE "icon: image," HERE
title: '',
animation: google.maps.Animation.DROP,
position: map.getCenter()
});
var markers = new Array();
//Creation de la bulle infowindow
var infowindow = new google.maps.InfoWindow();
Thanks very much … I will give this a go later.
Worked a treat – thanks for the help youyouk.
Useful stuff on googlemaps pins here: https://developers.google.com/chart/image/docs/gallery/dynamic_icons
Thanks youyouk, I haven’t had time to keep up with these questions lately.
Hi, where on the code it needs to be inserted?
Is it possible to have this so people can enter Australian Post codes, and not USA Zip codes?
Thanks for a great script.
You should be able to get this to work by changing the call to google maps to your country’s extension.
In the example files you’d replace:
http://maps.google.com/maps/api/js?sensor=false
with:
http://maps.google.com.au/maps/api/js?sensor=false
where should I put this to make the button find me work? Sorry.. I’m newbie.
onClick=
$(
Hi Alan,
Can you post what you’re trying to do on pastebin.com? Comment code from visitors is going to be stripped out.
If you want to just turn on the autogeocoding use (have it run automatically if it’s a compatible browser):
If you want to create a click to locate button you could replace the if statement on line 123 with something like this:
I want to edit infowindow style. I tried the options but not worked. any other way?
Yes, you can edit the stylesheet to make it look however you want it to. The css for the modal window begins on line 145 in the css/map.css file.
Hello Bjorn,
I think modal windows is different than Infowindow ?
Like jaydev,
I want to edit infowindow style with background color and border radius.
Any Idea?
Oh, yes I misread that. I don’t think you can just change the style of the infowindows very easily. I’d look into the InfoBubble library on this page: https://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries
Hello Bjorn, see the script is still doing very well and continues to help people out. I am looking to slightly change my implementation of the json script you kindly helped with.
Is it possible for me to change the ID names of ‘form id=”user-location”‘, ‘input id=”address”‘ & ‘input id=”submit”‘. I have changed form id to my own name in jquery.storelocator.js but cannot work out which fields to change for the latter 2, there are multiple entries in the js file for ‘address’ & ‘submit’.
Kind regards
Gary
Hi Bjorn, please ignore my post above, found out now where I was going wrong..
Thanks
I am having a problem that I am not able to scroll through my locations list (#loc-list) when I am on an Android phone. It works perfectly on my iPad on on any desktop, but when I am on my android phone, it doesn’t scroll. I can, however, scroll around the map with no problem, so there has to be a setting somewhere that I am not seeing that allows the scroll function to work.
Any ideas?
Hello Bjorn, I only display 2 results from my searchs, if I required the results to display horizontal rather than vertical would it be possible using the current css file?
Thanks
Oh yes.
It took me quite a bit of work to change it around.
http://jsfiddle.net/stillb4llin/CnHkP/
Will probably want to change your height to the right number… also, depending on the number of items depends on the % for width of the list.
I have this set up more for a mobile app….
Hope this gets you a start in the right direction.
Thanks! What file does this code need to go into? it will look alot better on my website with the list going horizontal
Hello Bjorn! I must first say this is quite an awesome piece of work; it really works great and I’m having a lot of fun with it. I am *VERY* new to jQuery and have been asked to put a store locator into my company’s mobile website and this has brought me light years closer to what they are looking for.
I’m trying to do something a little different; I wanted to make the list of nearby stores be a collapsible set; and although my code seems to be spitting out OK (if you grab it via a debugger and paste it into a static page it renders perfectly), because it is generated dynamically it’s not showing up as collapsible. From the things I’ve read, the DOM needs to be refreshed for it to show up as that sort of element. I’ve now reverted back to the original code (as they’d rather see it working than pretty, you know how it is 🙂 and wanted to try something simpler, so for the “loc-directions” div I tried to change the distLink to a “data-role=’button'”. Even this simple mod won’t show up as a link button, I’m guessing because of the reason stated above. Is there a simple line of code I can add to make this display correctly? Someone suggested “$(‘#element’).page();” but this doesn’t seem to work. Any help would be much appreciated.
And BTW, *Thank You* for such a wonderful script. It is really something else!
-Felix
If you provide an example from jsfiddle of your code and such, maybe I can look at it.
Hi Bjorn,
thats for the awesome script. Do you have any idea how i can parse the data (xml) via a string variable to your Java script function? I need to avoid to create a data file which someone could download.
Any advise is greatly appreciated.
Cheers,
Eric
PS: for someone interested in adding a little “waiting spinner” to it, add this to your code:
Inside the submit button div:
Add these line to the javascript file (jquery.storelocator.js) after row 198:
document.getElementById(‘sl_map_spinner’).style.display = ‘inline’;
and this after row 429:
document.getElementById(‘sl_map_spinner’).style.display = ‘none’;
Spinner gifs can be found through google, like this one:
http://www.markit.com/assets/images/spinner.gif
Do you have access to a database? I’d go with the JSON method if you don’t want a locations file to exist on the server.
Thank you Bjorn for the excellent plugin. I have what I think is an easy question.
When the page loads and no details for search have yet been entered, how can I display a zoomed out map of the US with the first 26 locations listed alphabetically? Or, just a map of the US so there is no empty space where the map container is?
http://www.travelpro.com/whereToBuy.cfm
Thank you!
Is there a way to show only the locations that are let’s say only 10 miles away? And if there are no it would just give an alert that no locations near? Thanks!
start here: jquery.storelocator.js file
var settings = $.extend( {
‘mapDiv’ : ‘map’,
‘listDiv’ : ‘list’,
‘formID’ : ‘user-location’,
‘inputID’ : ‘address’,
‘zoomLevel’ : 26,
‘pinColor’ : ‘fe7569’,
‘pinTextColor’ : ‘000000’,
‘storeLimit’ : 10,
‘distanceAlert’ : 60,
distanceAlert to 10
should work for you
Hi Nick,
I’ve added a new maximum distance option to the latest version of the plugin. To see how it works check out he maximum distance example link above.
This tool has made my life easier but I keep running into a problem…if I rename the XML file and change the name in the js file, it the tool no longer reads the file. This also happens when I open the XML, edit the contents and re-save. Any ideas? Does the XML need to be a specific encoding?
Thanks.
You want the character encoding to be UTF-8.
Hello Bjorn!
Compliments for your plugin, but for me is slightly compless! 😉
I use Wysisyg WB with your plugin and in theory for this, not have to change never, only write the shops in but not are all function mentioned on your site, or not work correctly because if it’s setting in “Store Locations” and the standard setting for DistanceAlert is 60 Miles. Not are more options you have writer on your site and if i modify one of pages published, then i insert others clients/shops in “store locator”, replace automatically all.
Now, if i want setting plus of 26 clients shops (i’ve up to 500), what is the istructions to modify it from Wysiwyg? Or parameter to change from A to Z and change from 1 to 500..?
And if want change the parameters of research from ZIP (in Italy is CAP) and region and city, separately? Is possible by Wysiwyg? The principal problem at moment is only the setting of “Store Locator Form ID” and “Store Locator Map ID”. If you have time and possibility, help me please..!
This is the interested site: http://www.switch-it-starter.com/negozi.php
Thanks.
Regards from Italy.
Andrea.
Hello Bjorn. You have visualized my request? Is a reply fot my problem?
Thanks
What is the reason to have zip and address in different boxes? One box that does it all is better. Less for user to mess up.
If you want to modify the the store limit look for
‘storeLimit’ : 26,
in the jquery.storelocator.js file. you aren’t going to be able to WYSIWYG with this file. open it up with a text editor. You will have to modify that field.
you will also need to modify
for (var y = 0; y <= storenum; y++)
{
var letter = String.fromCharCode("A".charCodeAt(0) + y);
change that from A…. to a number
You will also have to adjust your marker CSS.. should be able to do that in your WYSIWYG editor.
Good luck
I tried this but nothing seemed to change. It’s still showing letters and capping out at 26 even though i sent the store limit to 80
I just pushed a new version to Github that removes this limitation, among other things. I don’t have time tonight to update the documentation on this page but use those files instead. I’ll update this page tomorrow.
There is a way to change the red markers with a custom marker, let
Hi Cristiano! In the jquery.storelocator.js you’ll find this part:
++++ Original Code ++++
//Custom marker function – alphabetical
function createMarker(point, name, address, letter) {
//Set up pin icon with the Google Charts API for all of our markers
var pinImage = new google.maps.MarkerImage(“http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=” + letter + “|” + settings.pinColor + “|” + settings.pinTextColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
var pinShadow = new google.maps.MarkerImage(“http://chart.apis.google.com/chart?chst=d_map_pin_shadow”,
new google.maps.Size(40, 37),
new google.maps.Point(0, 0),
new google.maps.Point(12, 35));
++++ Replace that with the following code ++++
//Custom marker function – alphabetical
function createMarker(point, name, address, letter) {
//Set up pin icon with the Google Charts API for all of our markers
var pinImage =new google.maps.MarkerImage(‘path/to/marker-image.png’, null, null,
new google.maps.Point(14, 13)); // don’t forget to replace the path!
var pinShadow = new google.maps.MarkerImage(‘path/to/shadow-image.png’, null, null,
new google.maps.Point(14, 13)); // don’t forget to replace the path!
By the way I want to say THANK YOU BJORN for this amazing script!
Good luck Cristiano,
Tim
Hi, I am trying to link this in with Joomla – Has anyone done this before.
When i run the html file from your plugin on my server everything is fine, when i try add the code into joomla I get a blank page.
Any help would be appreciated.
Great Plugin and it is what I have been looking for 🙂
Thanks
Do you have a link to the page? Are you sure jQuery is being included?
i used on joomla article and it works fine
try using an to load the page that works into Joomla… That’s how I’ve worked around any issues with joomla.
http://www.w3schools.com/tags/tag_iframe.asp
It is probably because you need to change your infowindowTemplatePath and listTemplatePath. I had the same problem in Drupal and this fixed it 🙂
ciao,
about the zip code you must use maps.google.it instead of maps.google.com
and about the 26 stores, the plug in shows the closest 26 shops to your location
i have 220 stores in mine and if u change the zip code it shows to u the nearest.
about miles u have to change the distances in km. if u check all the discussion
u’ll find all the answers to your questions as i did for
http://www.fan3rush.com/sdt/index.php?option=com_content&view=article&id=82
hi,
tnx for the great work …
i would update my webpage with checkboxes using the “type” key in the xml
something like in the following link:
http://storelocator.googlecode.com/git/examples/panel.html
have u any advices ?
tnx
marco
ps btw to work on joomla i used the iframe tag 😉
Did you use the xml file and use the type field and then link that to the checkboxes to only display the type that was checkmarked?
Hello Bjorn,
Congrats for a very nice tool. Great work with this store locator plugin, it’s just what I’ve been looking for my current project.
I have also a question. How to insert, let’s say an icon that describe the type of store into the infowindow (i’m thinking at something like: img src=someimage.png. I have been playing around but it seems I can not get this to work. To say that my javascript/jquery knowledge is somewhat limited(i know, i am struggling with this). 🙂
Thanks,
Daniel
Where do you want this to show up at? what part of the display? An icon..what size?
Hello Nicholas, and thanks for replying.
I’m interested in showing an icon to reflect the type of marker in the infowindow. Currently I have in my xml file three types of locations that are being displayed into the infowindows in text format.
What I am trying to achieve is to place an icon before the text into the infowindows just for visual styling.
E.g. I have my infowindows structured like this:
…………………………………………
Address:
City:
Hours:
Phone:
Fax:
Text that describes marker type:
…………………………………………
What I am trying to achieve is
E.g.
Address:
City:
(small clock icon)Hours:
(small phone icon)Phone:
Fax:
(small location type icon)Text that describes marker type:
I hope you can understand what I’m trying to do here. I’m sure it exists a better way to do this.
Thank you,
Daniel
Hi Daniel,
I’m going to be releasing a new version within the next couple of days that will allow you to do this very easily. There are a lot of other updates and improvements so if you can wait until then it will be worth it.
cool stuff!
Hi there once more, is it possible to have the script search only uk locations? I have a store in Birmingham UK, when the user search for ‘Birmingham’ it shows Birmingham US instead of UK?
Thanks
u have to use maps.google.co.uk instead of maps.google.com
I used this which seems to work geocoder.geocode( {‘address’:request.term + ‘, UK’}
Cheers
LINK! How can anyone try to guess at your problem if you don’t provide a link!?
Hi Bjorn,
Thanks for this great script. Everything is working fine but I do not know how to show a marker for the initial location. The map is showing the exact location from the start perfectly, but I need a marker to show it more recognizable.
Can you tell me what code to implement and where to put it.
I have been trying
var marker=new google.maps.Marker({position:latlon,map:map,title:”You are here!”});
on several positions in the script but I can not get it to work
Thanks,
Arnout
Hi Arnout,
I’ve added a new originMarker option to the new version of the plugin, which is now available.
Hi, congratulations for this great plugin
I wanted to know how can I customize the information window that is showed when you click on a marker.
With the current version you’d edit the code in the create_infowindows function – line 455. However, I’m working on a large update that integrates Handlebars.js for much easier template updates. I’m hoping to release it within a day or two.
will u integrate selections on type field or something else operative ?
or it’s just an update on the template ?
anyway
tnx
Great 🙂
Here is a test page for the locator i’m trying to build:
http://belove.mybigcommerce.com/store-locator/
having trouble getting the modal window to fire. I’m using bigcommerce as the ecommerce backend for this, and when i click submit, i see a “loading” option at the top, which i know is part of bigcommerce. Is this code conflicting the reason why it won’t pop up? Any help would greatly be appreciated.
It can’t find your locations data file. If you check the console in Chrome developer tools or Firebug it will show any javascript errors. It’s looking here: http://belove.mybigcommerce.com/store-locator/locations.xml
Also, I should be able to release a new version of this plugin today, which has many updates and improvements.
great – i’ll try to redirect it. would that kill the modal window though?
BOOM! Worked great – this script is fantastic!
Eric,
I am also trying to get this to work in my BigCommerce store, but I have a feeling it is not loading the template files or that there may be a jQuery library conflict. Could you point me to your store locator page?
checking out the new version, are they not supposed to work offline? i’m not getting any activity with the source files.
Oh, the new jQuery reference probably doesn’t work from your local machine. If you have web server installed on your computer try that, otherwise upload it to a test directory on your server. Also, make sure you’re including Handlebars and the new template files. Handlebars is a new requirement for the plugin.
it’s all good – i’ve got it running and it’s 99% perfect. The updates are incredible – way to go!
I just have one small bug that i’m trying to figure out now, it seems that it kills my jqzoom on my page: http://belove.mybigcommerce.com/an-eagle-and-a-prayer/
any thoughts on why it would be doing that?
thanks again for your help!!!! Do you have a donation page?
I don’t see any errors but I noticed that you’re including jQuery twice – version 1.6.4 and 1.8.3. You’ll want at least version 1.7 for my plugin to work. I’d try just including it once first to see if that fixes it.
Hi please tell me theres a way to save stores, when a user hit button save it only show on page 2. Like favorites stores. And is there a way to have more then 1 picture at as flags? i have searched and searched but no luck so far.
I’m not sure what you mean by save stores. What would be saved and what would it save to? This is only a front-end plugin. If you mean save the user’s location preference, I think that would need to be handled by the developer integrating it into the site because it would likely be different for each case. You could easily add a “save” link to either template with the location ID but what you do with that is really up in the air and it goes beyond the scope of this plugin.
Unique marker images for each location isn’t currently supported but you could definitely add unique images to the templates (infowindow and list).
Hi again thx for your reply, im sry but my english is not the best. Lets save i have 4 stores thats displays on index.html and user clicks on a save button for store 3 and then goes to page favorites.html and it only shows store 3. Thx for help
About my other question so i have changed my icon pin marker from red with letter to an image and that works fine, but now i want to have 5 images to select about deppending on value from json like “+ storeIcon +” 1,2,3,4 or 5.
Are u from sweden? 🙂
/ ImSoHappy
Hi,
We want to use your store locator script, but we want to use wordpress with it…
We have a custom post type dealer and we are using Json api for wordpress to output our post type in json format. But it’s not a .json file
Its something like that : http://mywebsite.com/?json=get_recent_posts&post_type=detaillants&custom_fields=wpcf-locname,wpcf-lat,wpcf-lng
Can we use this URL in the datalocation or is there a way for doing this?
Thanks
Yes, definitely. Just use the full URL that outputs the JSON for the dataLocation option. It most cases the location of the JSON data will be a URL. I just used a file because I didn’t want to give the impression that any back-end work was required for this plugin to work.
Ok…
So if my variable are different that yours… locname = wpcf-locname does i need to change someting somewhere? jquery-store-locator.js
Yes, see lines 336-349. So, for name it looks like you’d want:
I got this error :
ReferenceError: locname is not defined
var name = this.wpcf-locname;
I got this for my field in my json file
..,”custom_fields”:{“wpcf-locname”:[“Oktane Design”],”wpcf-lat”:[“45.882144″],”wpcf-lng”:[“-72.486421”]}}]}
Try:
TypeError: this.custom_fields is undefined
[Stopper sur une erreur]
var name = this.custom_fields.wpcf-locname;
I need to see an example of the full JSON structure in order to be helpful. If you can, post the data on pastebin or reply with a URL.
Hi Bjorn !, Nice Job!, It has been very helpful for me. I have a question, if you can help me, I need that I may appear markers as a filter on the list, as a category of markers, but I am not able to do so because I find no way to change it in your code, you may be able to help me, I appreciate it, thank you very much.. This link is to a site that I want to see if I can do the same http://www.guiamap.com/mapa.php?city=1
Ernesto
Great tool, love it!
I’m having problems with the xml file path. I need to put the xml file a directory up, so something like this: ‘dataLocation’: ‘../Maps/locations.xml’, or even: ‘dataLocation’: ‘http://domainName.com/Maps/locations.xml’ , but neither of those paths work(locally and on the server). It works fine locally when I use: ‘dataLocation’: ‘locations.xml’ .. but the way our CMS system is setup I can’t upload the xml to the same directory.
Any ideas?
Thanks!
Maybe try using the full path to the file. If you’re on Linux, something like /home/www/… If you’re using PHP you can use the getcwd() function to find it.
no luck 🙁 Still trying to figure this out. – not using php. Any other suggestions?
Thanks!
Have you tried just a relative path yet from the web root? Like: ‘/Maps/locations.xml’
yes, that is not working either.
I did a test, putting the XML file one step up, and this worked for me:
Are you on a Apache or IIS server? Also, what CMS?
Hello,
this is amazing and worked great. Suddently 4 days ago it is not work anymore. Did something changed i.e. google api which could effect the map is no longer displayed?
Many thanks
Not that I’m aware of. All the demo examples above are still working. Did anything else on your site change? Or did you upgrade the plugin to the latest version? There are new requirements (Handlebars.js) for the latest version of this plugin and a couple of the option names have changed.
works perfect again!
(there was an xml loading issue with a new database entry)
Hello, i try you’re plugin in IE7 and he doesn’t work, it’s normal ?!
but i love it thx for this
oh, unfortunately, i disabled the js on IE7.. x) sorry
other question, it’s possible to run this script from jquery 1.4.2?
You need at least 1.7 for this to work.
yes i know, but my website turn with jquery 1.4.2 i cant use you’re script,
there is nothing to make possible to make it work in 1.4.2?
Can’t you update to a newer version? 1.4.2 is almost 3 years old.
If you want to change the code I think it should work if you change the instances of .on() back to .click() and .submit(). I’d really just recommend updating jQuery though.
i know.. in my personnal website i use 1.8.3 but for my works, he uses 1.4.2…. -_-
i try you’re suggestion thx 🙂
he doesn’t work 🙁
Hi Bjorn,
This is a great update and a great plugin, thanks! I only was wondering why you have on line 224
var userinput = $(‘#’ + settings.formContainerDiv + ‘ #’ + settings.inputID).val();
when the inputid is unique? because an id is always unique.
so you can also make it like this:
var userinput = $(‘#’ + settings.inputID).val();
best regards,
JP
I don’t remember at the moment if there was a specific reason – I was probably just thinking better targeting. I write a lot of CSS so I’m used to making selectors granular. I will check out performance comparisons to see if it makes any difference.
I also changed the keyup on line 271 to $(document).keypress(function (e) {
because when you have keyup, it still postsback. As Kenneth comments on this question http://stackoverflow.com/questions/1563062/prevent-form-submission-with-enter-key
I’m using preventDefault() in the get_form_values function, which should stop any default submission.
Hi Bjorn,
Great plugin been using it everywhere I can. Just wondering in the UK we have postcodes like SW1, and when we search for them the map will goto a place in Germany. Just wondering if there away to stop that and have it only goto places in the UK? I’ve tried using maps.google.co.uk but no luck.
Would be great if you could point out my idiocy or maybe have another method to fix it 🙂
Thanks
Mc
Can you try replacing line 121 with the following in jquery.storelocator.js and letting me know if it works for you?
Nevermind on that last post. They use the following example in the API examples:
http://maps.google.com/maps/api/js?sensor=false®ion=UK
hello,
what is a maximum store locator that i put in .xml ?
I have 8000 stores… it’s ok for the plugin ?
There really isn’t a limit but I’m not sure at what point the performance would start to degrade. I haven’t had a chance to try it with that many locations. If you are able to test it let me know how it performs.
if you want try with many location i have .xml but you need to edit some field
http://www.artsx.fr/storelocator.xml
I think i have one error somewhere in one of the lines because he doesn’t work when i try after edit field.
You can test if you want, i puts on tonight !
I edited the file
I added the files to the plugin works, I’ve tried with one, I put the minimum information required for the plugin to work.
I do not know if I forgot something or if I make a mistake somewhere ..
oh yeah, it’s working !
but i have error when i put on input the adress.
he makes me “ZERO_RESULT”
i’ve add button for geolocalize me on the jquery.Store.locator.js (i see on prev comment the code for add this but i think i dont add this correctly
if you want check this : http://www.artsx.fr/storelocator/
Hi Jihane,
I saw your post about loading 8000 stores in the map, and I saw your example http://www.artsx.fr/storelocator/
Did you finally make it work with thounsands of stores?
It seem it only loads a few…
joseanmola@hotmail.com
it works !
i forget to change containerdiv ID… 🙁 lol
hi – you’ve done great work (best of the free store locators I’ve seen), and I have just 1 question:
Using the Maximum Distance example, when doing a search is it possible to first clear any *existing* results from the location list panel before showing the new results? This is because if you run multiple searches of different locations (different states, just for example) the results of the different searches are merged together even though they could be in vastly different locations much further than the specified distance.
Thanks so much for any help! 🙂
Vincent
The data should reset when you submit the form again. Is it not working that way?
no, it will add it to previous searches run in the same session, for example if I’m check multiple postcodes in one visit and it only finds one or two results it will merge it with previous results based on distance.
Alright, that’s a bug then. I’ll work on fixing it. My intention was to have it reset on every search.
Thanks Bjorn – I really appreciate it 🙂
Vincent
A fix will be in the next version, which should be up this weekend. If you need it sooner you can add the following after line 288:
Thanks so much Bjorn – I’ll test that as soon as possible!
Vincent
New version of script works perfectly with max distance and clearing old results before listing new finds – thanks so much! Great work.
Vincent
Hi,
I was wondering if it is possible to still show the default map onload (or fullMapStart) and use the maxdistance feature. If I turn the maxdistance feature to true and the fullMapStart to true, I get an alert stating “Unfortunately, our closest location is more than undefined miles away.” But if I exit that alert and enter an address and select a mileage distance – it works as expected.
Any help would be awesome. Great script!
I’m trying to think of a way to do this but I’m having difficulty. By having both set, the script basically needs to ignore the maxDistance setting the first time the page loads but then ignore the fullMapStart setting when the form is actually submitted. I don’t want to require cookies. I’m not sure yet if I’m going to be able to get this to work.
This should be working now in the latest version that I pushed to Github last night (1.4.2).
HI,
My problem is that i want to show the stores which are in the radious or distance from the given store.
What should i do for this plugin by changing the Jason file.
Can anyone help me.
Thanks!
Hello,
it’s possible to add a loading while the map loads to understand that the script is in the process of turning it to wait?
It’s pretty easy to do with jQuery. I’m adding an option in the next version, which I think should be released tonight or tomorrow.
I’ve added a loading option in the latest version, which is now on Github.
One fast question. I need to know if you can point me in the right direction on the using of a start pin. I see the ‘origion marker’ option, and have set it to true, but nothing happens, and so I just needed to know what I needed to be looking for to fix the issue.
Thanks
Are you using any other options?
Bjorn,
Thanks for this great plug-in, works beautifully.
Quick question, I tried using the show origin marker… but it doesn’t show….
Are you using any other options? It should just show a blue marker in the center.
Now works.
Awesome plug-in, although I can’t seem to get it to work with over 114 entries. Any suggestions?
Using XML? Someone above has it working with 8,000 locations and I’ve tried that data myself and it works. I’d guess that you have invalid characters in the 115th location. You can also use the W3C for validation on the data: http://validator.w3.org/
I’m trying to use your plugin right “out of the box” locally, and I can’t get it to work. When I search the map pulls up but the panel area does not. And it’s only showing 1 marker in all of MN, with not info box.
Does it only work on the server and not locally?
Thanks!
Change the jQuery call if you want to run it locally:
http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
I did that(sorry should have mentioned that), looks like the jQuery is working correctly. I just looked at the Firefox FireBug console, I’m getting this error: “not well-formed {{#location}}”
Hmm… yeah, I’d recommend running it on an actual web server – it doesn’t seem to run just from a directory on a local machine. XAMPP, AMMPS, WAMP, etc. if you want to set up an easy local web server. I can look into seeing why it doesn’t just run from a directory, it looks like it’s something to do with the template files.
Just uploaded it to a test server, works on the server perfectly. It would be nice if I could test locally for some future projects, but definitely not a deal breaker!
Thanks!
I probably should add that the jQuery link is the ONLY thing I changed. everything else is as it was on download. I’ve tried several of the example pages and it’s the same error.
Why won’t the json example accept any special characters?
I’ve changed the “” tag in json-example.html to “” and if I type with special characters in the it shows them correctly, but the data from the “locations.json” file won’t show special characters. They are replaced with “�”.
I’ve also tried adding “contentType: “application/json; charset=utf-8″” after line 302 in the jquery.storelocator.js file.
Do you know what is wrong?
Thanks
edit: I’ve changed the meta tag in json-example.html to meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″
The meta tag is currently in HTML5 form. Have you tried seeing if the JSON data validates? http://jsonlint.com/
Yes it is valid JSON. In fact all I did was editing one of your shops name in locations.json from “Chipotle Minneapolis” to “Chipotle Minneapolis” (with special characters instead) and the result was: Ch�p�tl� Minneapolis.
I’ve tested this on localhost and in firefox, chrome and internet explorer.
I tried copying in some special characters into the JSON file on my local setup and couldn’t reproduce your issue. Can you possibly try on another server? Also, what program are you using to edit the files?
I am programming in NetBeans IDE 7.2.1, i don’t know if it has something to do with this program or if I made a mistake myself, but after trying this in Dreamweaver it worked without any errors/problems.
Hello,
You think it’s possible to add two loc_list at the same time?
one for the research you put and secondary with city around ?
I’m not sure I understand what you mean. You could have two location lists if you wanted. Line 721 in version 1.4.2 is where I’m appending the list html.
Hello,
I love the plugin! Just one question how does it calculate the distance between the input and closest location?
In my example it shows me from zip 07755 to 11206 (which is one of the locations) as 30.16 miles, but when I hit the directions button and it takes me to google it gives me 3 suggested routes which range from 58.2 miles to 62.7
The issue I have with this is that there is a closer location to this (I am only showing 1 location at a time as per clients wishes) which is 42 miles… yet it shows this one because according to whatever the calculation is its only 30.16 miles.
Any advise or help?
If you check the “A note on the distance calculation” above that details the current distance measurement. I’ll most likely add an option for the Distance Matrix API in the future but I’m not sure when at this point.
Hi Bjorn, have you done any versions of this where the form autocompletes?
I haven’t done anything like that yet.
I’m working on that part now 🙂
How about anything where locations have “features” checkboxes? IE- Drivethrough, Dine in, Accepts cc’s, etc?
Nope, haven’t done anything like that yet either.
Hi
Love the script, I just want to acheive one thing that I can’t work out. Using the XML file and the type attribute, I want to display different coloured marker for the different types in the xml file. There will only be 2 different types. I can’t work out how to do it.
Is it possible to set the type attribute to a global variable that I could then use in the following function to change the pincolour? A previous commentor was doing it this way, but I could not understand how they applied th Type attribute from the xml file to use as the if/else key.
Any help would be most appreciated.
James
//Custom marker function – alphabetical
function createMarker(point, name, address, letter) {
//Set up pin icon with the Google Charts API for all of our markers
var pinImage = new google.maps.MarkerImage(“http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=” + letter + “|” + settings.pinColor + “|” + settings.pinTextColor,
new google.maps.Size(21, 34),
new google.maps.Point(0,0),
new google.maps.Point(10, 34));
var pinShadow = new google.maps.MarkerImage(“http://chart.apis.google.com/chart?chst=d_map_pin_shadow”,
new google.maps.Size(40, 37),
new google.maps.Point(0, 0),
new google.maps.Point(12, 35));
It’s basically a matter of passing a new type variable down to the correct spot. I’ll likely make it so this is easier in next version. For XML you can do the following:
After line 446 under the “Process XML” section add:
A few lines after that, where the locationset arrays are being defined on 453 and 460, add “type” to the end. Example for the first one:
Then, on line 690 add “locationset[y][14]” as the last parameter for createMarker:
In the definition of the createMarker function on line 752 add “type”:
Then you could do something like this (using Bank as a second type) at the beginning of that function:
Then, on 754 where Image is defined just replace settings.pinColor with pinColorOverride.
Hi Bjorn
Thanks you so much for your reply, it all worked perfectly.
I now need to pass that ‘type’ variable through to the location-list-description.html template, so i can add the type variable as a class on the list-label div so I can match the colour to the markers I am using.
IS there something else I need to do to pass the type variable to the list template document? It does not seem to be working after implementing the changes above. Adding {{type}} in does not add any value.
Thank you in advance if you are able to help and thanks you for the plugin it is great.
James
Just a couple more things to get it to the templates:
Declare storeType as a new variable along with the others on current line 490.
At the bottom of the create_location_variables function add:
Then look for the “Define location data” comment around line 557 and in the else add the following after origin (be sure to add a comma after origin before adding the new line):
That should allow you to use {{type}} in the templates.
I assume this goes back to storeLocator v1.3.3 what I’m using as well. I hope, you Bjorn, James or someone else could still help me out. I’m not getting this working. All markers show the blue color even if I swap the values between the if…else function.
(I’m looking at a part on my map/data where I see both, places who should be shown ‘red’ and ‘blue’)
I added all, did the following changes:
a) under the “Process XML” section add:
var type = $(this).attr(‘MYXMLNAME’);
as my var inside xml is not called ‘type’
b) createMarker:
function createMarker(point, name, address, letter, type) {
if(type=== “MYTYPE”){
var pinColorOverride = “6991fd”;
}
else{
var pinColorOverride = “fe7569”;
}
as my value is not ‘Bank’
—
Further question, where do I place
“type”: storeType? Couldn’t locate the exact place.
Many thanks,
Tobi
I assume in the latest version type has been replaced by category??? It seems to have worked for me using the category variable.
Dear Bjorn,
I love your script, because our network only support ASP as server script.
And i dont know anything about that.
So this script is the perfect solution.
I have only one problem, when i am testing the script, local on my computer.
Then the form wil not submit in Firefox or Chrome. Safari is no problem.
I can’t test IE, because it isn’t installed on this mac.
Do you have a fix for this problem.
With kind regards,
Laura (the Netherlands)
Are you running it from a directory on your computer or a local web server? It won’t run from just a directory.
I’am running it from a directory on my computer. I will try it on our webserver.
Hi,
The script is working on the server. Thank you very much.
I can’t figure out, where i can change “directions” in the results.
Because i want to change it in to Dutch.
And how can i change miles to km.
Greetings Laura
There is an option for kilometers:
For the directions text you can change that in the template files (/templates directory). If you’re using XML or JSON you’d want to edit the location-list-description.html file.
I could not get km working by parsing it in from the html file, so I just hard coded it in the end.
Dear Laura,
could you help me out? I can’t seem to make the side bar with location info to appear.
My map with locations does work by the way.
Rgds,
CJ (Netherlands)
Hello Bjorn,
your script is GREAT!
However, how can modify this to integrate img src ?
e.g
<marker img="” name= “test” lat= “43.586117” lng= “7.036627” type= “” address= “6250 MOUGINS. France” address2= “” city= “” state= “” postal= “0” phone= “” web= “” hours1= “0” hours2= “0” hours3= “0”/>
{{#location}}
{{marker}}
{{img}}
{{name}}
{{address}}
{{address2}}
{{city}}, {{state}} {{postal}}
{{phone}}
{{web}}
{{#if distance}}{{distance}} {{length}}
Directions{{/if}}
{{/location}}
Please i need some help to attach a picture for each ID.
Greetings Med
If you go up a couple of comments this is basically the same question that “James” had. Instead of “type” just create image variables.
I can’t seem to get the example to work for me. I’ve checked all my links and made sure I’m using the right scripts but it still won’t ‘go’. All I’m getting is a blank when I hit the submit button.
http://www.fxi.com/html/store/
It looks like you didn’t upload the templates: http://www.fxi.com/html/store/templates/infowindow-description.html
/facepalm. That was it! Thanks. 🙂
Hi Bjorn,
I have 2 questions.
first one, In IE stands the cursor on the letters. So you can
alright xD the second part disappeared.
Second one, when there is more than 60 miles in between you get a pop up. Do you know where i can change it to Dutch?
My boses are very pleased, because i found your script. So thank you very much
Second question: You can find the text in the jquery.storelocator.js on line 477 and 483. I see there’s a bug there, which should display kilometers if you have that option selected. I’ll fix that in the next version.
I don’t think I understand your first question. Do you want a different cursor for the location list?
Hi,
Some part of my question disappeared.
The question was.
In the input field for to zipcode or streetname.
The text cursor is on the last letter you typed. This allows you not see what you typed. This happens only in Internet Explorer. While Firefox and Chrome put the text cursor after the letter.
I’m still not sure I understand. Does this happen in the demo links above?
http://heditex.com//WSData/WSStyle/Bodiax/images/vb.jpg (screenshot what happens on our site)
Its only in IE.
It doesn’t happen in the demo above.
It must be some other CSS on your site. I’d try using the Internet Explorer developer tools to see if you can narrow it down.
Hi Bjorn, I was trying your demo and I wanted to know is there a way to remove the list on the left of the map and just leave the map to show the markers of the locations.
second, how can I change it to take dynamic radius. So if the user wants to see with a certain radius and there is field in the form, how can I do that.
Thanks
You should be able to remove the left list by commenting out or removing line 721:
For the second question, please see the max distance example above.
Hi Bjorn, Sorry you mentioned looking at the max distance example, I was not able to locate which example you were talking about.
I basically have a form that takes a
– Postal code/ zip code
– street address
– country and
– radius
I want the app to look for the location within the radius specified by the user in the form.
so for example user enters a postal code or street address and selects radius of 6 miles, I want the results to be displayed within the 6 mile radius of the postal code or address entered by the user.
also if the user doesn’t enter any postal code or address and just selects a country example Canada them I want the app to display all the stores in that country.
could you please point out where I need to make changes to add this functionality.
Thank you very much and again you have done a very good job this application.
Maximum distance example: http://bjornblog.com/storelocator/maxdistance-example.html
Zip code or address can be entered into the main address field. If you want to separate them out I’m not going to be able to assist you with that.
Use the fullMapStart option if you want to start with all locations or set the zoomLevel to 0 to automatically center and zoom.
I am also trying to do this: “if the user doesn’t enter any postal code or address and just selects a country example Canada them I want the app to display all the stores in that country.” but didn’t see any answer for how to do this. It seems they HAVE to enter something in the address field to get results for their country, otherwise it just continues to show US matches which is very confusing for the customer.
I worked on this myself and did come up with a working solution, I dropped in a list of the countries in my database with the average latitude and longitude for each (you can download a csv of all of them here: https://dev.maxmind.com/geoip/legacy/codes/country_latlon/) and used that when the address is blank to reverseGeocode an address, and used that to load my matches for the country. Wasn’t too hard to do and might make a nice update to the code. I’d prefer it to center on the first match in the list rather then the country lat/long so still looking for how I can get it to do that as well.
Hi Bjorn,
above is the location.xml with just one location for now. When in the setting I turned “defaultLoc” to “true” I get error popups saying unable to locate.
could you please see what’s wrong with the location address. I really don’t know why it’s not able to find it.
Thanks.
You need to set a default latitude (defaultLat) and default longitude (defaultLng) if you want to use the default location option. Please read the documentation above.
thanks, I actually didn’t notice them.
I have another question. How do I make sure that most of the closest location’s of the stores are visible. currently the location that is closest is always of the screen, in a sense that I have to scroll the map to see the marker.
I mean to ask is that, is there a way to draw the map so that some of them or even the most closest location is centered because seeing that is more important than may the other things.
Thanks once again.
Change the default zoom level with the zoomLevel option. If you want it to zoom and center automatically set the zoomLevl to 0.
Sorry the location xml is for some reason not getting posted, here is the link to the location.xml file.
http://jbcomp1920.net63.net/locations.xml
just adding the msg again:
above is the location.xml with just one location for now. When in the setting I turned
I’m facing a very odd thing right now. I managed to get a variable replaced by images(stars).
When a variable stars has a value 3 for exemple, an image of 3 stars is displayed in Infowindow and list. I made up this for 5 stars, but only the 4stars image and 5stars images are displayed.
For the others nothing happens. Can you help me to find the problem ? And sorry for my english
Problem solved !! I just had to handle the css and it worked perfectly. But another problem appeared
when I tried to put it in my Joomla site. Apparently, store locator is facing the conflict with Mootools.
Are you using noConflict? http://api.jquery.com/jQuery.noConflict/
You should definitely be using it if you’re running jQuery and Mootools on the same site.
Thank you for you answer Bjorn ! Actually the problem (still) isn’t there, cause I implemented
JQuery Autocomplete for the searchbox and JQuery simplemodal to replace alert() by modal windows. And it works. The problem is the map does not display. I’m sure that the problem is in my JSON file parsing, different in Joomla, but I don’t know to do this. I want to use it for my component.
LOVE LOVE LOVE this Bjorn! I added a list where each option value matched the markerId in the map list and added this in the “//Handle clicks from the list” section:
var selectedMarker = markers[markerId];
$(“#dealer option:eq(“+markerId+”)”).attr(“selected”, “selected”);
Is there a way that I can have the select dropdown change the item that is selected in the list?
Also, I am using latitude and longitude to pull up locations by distance… However, when the map loads it does not have the first location selected on the map.. Is there a way to have it automatically select the first location in the list and have it open up the info bubble for that location on the map?
It doesn’t select or open the first infowindow by default but it’s not very difficult to add:
On line 697 in the for loop change the create_infowindow(marker) to:
In the create_infowindow function after the last else (817) add the following to pop up the first infowindow (the first one on the list will always be the closest):
Above that, after setting the list li background colors (747) add the following to focus on the first list item, which will be the closest:
For your first question, you’re adding a drop down in addition to the list? Are you using the markerID as the option value? If yes to both of those I think you’d want to do something like this after the “handle clicks from list” code (it’s going to be very similar to that):
Then in the create_infowindow function I think it would be alright to change the first if statement to:
Hey Bjorn,
I was able to get the dropdown working… However, I am still having problems with it selecting the first marker on load.
I changed this:
create_infowindow(marker);
to this:
create_infowindow(marker, null, y);
and also added:
if(loc_num === 0){
infowindow.setContent(formattedAddress);
infowindow.open(marker.get(settings.mapDiv), marker);
}
It is not working however and I believe that it is because “loc_num” is not defined anywhere in the document.
If I define:
var loc_num = 0;
it will open the infowindow for the farthest location(probably because it was last to load).
Any thoughts?
Oh, I missed a step:
Change function create_infowindow(marker, location){ to:
This would be a nice feature to implement as a paramater, it works with the above code but the location is not centered.
This worked for me. Try changing this:
To this:
I tried the hardest I could to integrate the plugin into my Joomla component but it doesn’t work.I have a problem with Json and the DataLocation settings becauce actually in Joomla, I don’t know how to use it. Any idea ? That’s Very frustrating, because that’s the only thing which cannot work in the component, and keeps me stuck on the project.
Thanks by advance to the one who will give me an answer.
Do you have a link where I can see it?
Sorry that my answer took so long, I finally solved this myself, by integrating it as a wrapper in the component installation folder. By the way I have another question: how is it possible to integrate a filter system with checkboxes, which displays and zoom on only the markers category ? Is it possible ?
Heej Bjorn,
I have a question,
By a few entries i want to add a “star”-image, in the location-list. It doesn’t have to show on the map.
Where and how can change this?
Thanks once again
Laura
I solved it myself.
Great, glad you were able to figure it out.
Hi Bjorn,
Today our website has been launched.
http://www.bodiax.com/default.aspx?wsmt=wscontent&code=Info%20|%20Dealerlocator
On this page you can find the dealer locator.
Only one little issue.
The popup marker displays something, that i dont wanna show. “star.gif”.
In the xml file, it is subject to “Hours1”.
How can i change this.
Thank you very much
That’s looking great. It looks like you’d want to remove Hours 1 from the template. Just open /templates/infowindow-description.html and remove the hours1 line (line 6).
Hi Bjorn, your plugin is really awesome, I’m experimenting with it these days and it offers an incredible depth. I really love it.
I’ve got a question, and I dunno if it’s possible…
I have a few “main” stores that I’d like to show first; it doesn’t matter the distance from my starting point. let’s say that store 1 is 40 km away, store 2 is 30 and store 3 is 60, but it’s marked as a main store too.
the normal order should be store 2, store 1 and store 3, but the one I’d like to get is Store 3 (main one), store 2 and finally store 1.
Is it possible?
Cheers!
Sorry, I’ve been really busy lately. I’ve tried a couple of things but haven’t gotten it to work correctly yet. I’m going to try to figure this out.
Thank you Bjorn for the help.
Hi Bjorn, could you please explain how fullmapstart = true works, how is it able to get all the locations in the xml file without looping.
I want to make a change where it can only get the location of a particular country selected based on the form.
Thanks
jQuery Conflict:
Hello, I’m having an issue with a theme I’m using in WordPress, which uses a different version of jQuery. When I add , the maps work beautifully but it breaks some of the functionality on the website. Is there a way to use jQuery 1.9.2 or whatever version my theme is using?
Thank you for a great script!
Also, second question that I forgot to include:
I want to add small icons to the locations list for the services specific locations have. I’m looking at the location-list-description.html template and think the best way to do it would be to have something like IF LOCATION X, , IF LOCATION Y, , etc. I’m just not sure how to put that in the template. Is it JS?
What version of WordPress are you running? WordPress includes jQuery automatically, so you don’t want to include it again. Hopefully your theme isn’t including some old version of jQuery. The proper way to set it up in WordPress would be to edit an existing JavaScript file in your theme, if one exists (there may be one for general scripts), or create a new JavaScript file and include it via wp_enqueue_script in your theme’s functions.php file or a custom plugin. You could also add it in your theme’s header or footer file but it’s not the best way. jQuery is namespaced in WordPress so you need to use jQuery instead of the dollar symbol for the call:
Will there be an icon for each individual locaiton or will there be icon categories?
Great, thank you. I’ll take a look at the jQuery files.
Each location will have a combination of services, like categories (i.e. gas station, lotto station, car wash). We just want to display the icon for the service that’s applicable to the location. I don’t mind setting the icons manually for each location.
There are the jQuery references in the theme I’m using. When I remove the one for your plugin, the site works as designed but the map is not displayed.
script type=’text/javascript’ src=’/wp-includes/js/jquery/ui/jquery.ui.core.min.js?ver=1.9.2′>
I may just make a custom template for the location page if the theme is incompatible.
Last reply on jQuery: wordpress currently uses 1.8.3. WordPress 3.6 (scheduled for end of April) will use 1.9. Until then, I’m going the custom page route.
Any thoughts on the services category icons?
Unless there is a better way, I just added another field in the XML and will set the icons per location.
Sorry, yes – that’s what I’d recommend doing. I have a category field in the latest version of the plugin that is passed to the templates. It was previously “type” but it wasn’t completely set up.
On the jQuery thing. The first thing you mentioned with version 1.9.2 is jQuery UI, which is separate from jQuery.
Bjorn,
I’ve seen the category field in your latest version. Is it possible to filter on this field? Like you do with the max distance option?
For example:
Enter your address / zip code, select a distance and select a categorie.
Edit: Disregarded comment
Disregard that last comment, it doesn’t work. If you skip down to comments by Devin you’ll find a full example that I posted.
Hi Bjorn, Could you help me with modifying fullmapstart to only display a certain countries locations.
I want that when the page is first loaded, it should display all the location that are in Canada, even though it has locations in other countries.
Could you please give me some input in this. Thanks you
I’m not sure if it would work for this situation but have you tried setting the region as described above in step 4 under usage – “Region targeting example”
Love this plugin. I’ll be using it for a major u.s. corporations website. I’ll link you when it’s fully customized. I wanted to know how I can style the infoWindow a bit more than what’s offered in the infoWindow template file. I was hoping to change the entire look of the window, not just the contents. Example, I want to change the close X and also the way the corners and drop shadow. etc… any suggestions?
Hi, 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
I haven’t tried working with it at all but I’ve read that it has worked for people.
Hello Bjorn,
Do you know if there is a solution to list two stores of the same location inside the map bubble?
i.e.
Store A and Store B are sharing/next to each other the same address
– show on map as A or either B (that is the current situation)
-> click on google map marker shows Store B under Store A
Thank you
That would be a more general Google Maps issue. You might find some ideas here: http://stackoverflow.com/questions/3548920/google-maps-api-v3-multiple-markers-on-exact-same-spot
Hi,
I would really like to use a custom marker on my map. I THINK Ive found where to change the pinImage, but it is not working. Could you please show me which lines to manipulate to use my own icon? Thank you so much for such an incredible plugin.
ben
It depends on how many locations you’re showing at once. If you’re using the default settings with the marker letters, the marker is set up with line 773 to 780 (assuming you’re using the latest version). Line 773 is the path to the image – you’d change what’s in the parentheses. The next line sets up the dimensions of the image and the next 2 lines deal with placement. The four lines after that set up the marker shadow. There are some more examples here: https://developers.google.com/maps/documentation/javascript/overlays#Icons
Hey,
Great job with this store locator! I have been wanting to figure out how to do this; however, I am stuck…. How do I change the Chipolte to another company and its locations and show the results?
You need to decide how you want to pull in the location data. You can create a new XML file based on the example that’s bundled with the plugin. Alternatively you can use JSON or KML. KML is easiest if you want to create a My Map on Google Maps and export the data: http://support.google.com/maps/bin/answer.py?hl=en&answer=62843
Hey,
I think I’ve got everything setup correctly. Unfortunately none of my locations are showing on the google map. I’m guessing I’m not sending all the required fields. What fields are required?
Currently, the only fields I’m sending are:
locname
address
city
state
postal
web
Do I need to add in lat and lng? Anything else? My client didn’t provide lat/lng, might be a manual effort.
Thanks,
Max
Adding a lat/lng worked! Sigh 🙂
Yep, you need to add the latitude and longitude. If you’re looking for an easier way you can sign in to Google and go to Google Maps, create a “My Map” and export the KML to use in place of XML. http://support.google.com/maps/bin/answer.py?hl=en&answer=62843
Hey Bjorn, love the plugin. I have added a recaptcha to the form, but since the form is in ajax, the map still reloads whether or not the captcha was entered. Any ideas on how I can make it work ?
I think I would try to validate Recaptcha with AJAX first. You could add it into the begin_mapping function that starts on line 250, which is where the plugin gets the form input value. I haven’t tried it myself but you might be able to work off this example: http://snipplr.com/view/15563/
Love this feature, but we have a small problem.
We are seeing some of our users typing in a CITY only – like PORTLAND.
And as a result the script defaults to the most obvious PORTLAND – Washington.
However, we are using this for a company in North West Indiana. And there is a Portland there (near Gary).
Any way, we can force it to look in a certain area “first”????
thoughts
Hello,
The search box essentially functions the same way that the search box does on maps.google.com. If you’re using this for one state I’d recommend using a more specific label on the input field to give the user more direction. You could either have it tell people to enter the state along with the city or you could just have “city” as the label and add the state to the value that the user inputs. If you want to do the latter you could add a line after line 261 (after the check for a blank value) such as:
As far as I know the Google Maps API only does region biasing based on country. If you wanted to get fancy you could do an IP lookup with a back-end language.
P.S. Oregon not Washington 😉
Thanks for the ideas…
And, maybe I should go back to 5th grade Geography class…. Oh well…
I think we’re going to take the user input and test to see if it has numbers. If there are NOT numbers, we may assume it is JUST a City and add a state value to it.
Is it possible to have the search look for a field in the XML also? Name for example?
The search is currently all location based – everything is displayed in relation to an origin location. I’m not sure how searching by name would function.
Hi,
This is the best store locator. I have ever used. Thanks for that.
Is there a way to show the directions inside the store locator instead of going to the google maps??
Hi, the plugin is currently not capable of doing this. I may add it in at some point in the future.
hi bjorn,
i’m already using your plugin with xml file,
now upgrading to ver.1.4 i would try to use the kml file generated by google maps.
everything it’s working and my question is:
is there the way to use the icons listed in the file?
http://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png
it could be very amazing considering that we can upload our icons on google map.
tnx a lot
_
marco
arghhhh the text has been lost:
http: //maps.gstatic.com /mapfiles/ms2/micons/blue-dot.png
For KML the icons are currently not pulled but I’ll try to get that in the next version.
tnx a lot
i’ll wait for the new release to upgrade 🙂
great job
Hi Bjorn,
My bosses found a problem.
When someone put in a zip code, the locator shows them 5 results.
We have 2 kind of dealers (star and normal). When there are in one city more then 5 dealers like “Vlaardingen”. He doesn’t show any star dealer, they pay for it.
My question is:
Is it possible to put the star-dealer first in the search result in a radius of let’s say 20 km. And then the normal dealers.
http://bodiax.com/default.aspx?wsmt=wscontent&code=Info%20|%20Dealerlocator
I hope it’s possible
Hi,
Is it possible to use multiple KMLs with this? I have a KML with my store locations, but I also have another KML with polygons that I would like to overlay.
Right now the plugin is just set up to read the location data from one file.
Hi Bjorn
im trying to add a few simple categories that i can filter by the results by. i read the previous comments and tried adding if(locationset[y][14] === selectedCat){ on line 705. It seems to work sorting the markers but now my list wont display? I think i might be placing the if statement in the wrong line? Any advice would creating categories would be great!
thanks in advance!
I think I see what you mean and I’m looking into it.
Thanks Bjorn!
Here is link to an example of what im trying to do. http://weareshowpony.com/locator/ using the checkboxes filter by the 3 categories.
Here’s a much easier solution that I’ve tested and it’s working. I used a select box in my test environment but you should still be able to work off of it.
In the begin_mapping function get the value of the category that you want. Ex:
In the same function about 13 lines down the mapping function is called. Pass the selected category:
In the mapping function get the selected category:
Where the locationset array is created, you’ll want to check the category before adding the location – you’ll see comments for “Process JSON,” “Process KML” and “Process XML.” So, assuming you’re using XML and you’re not using the maximum distance option, you’d make the following change around line 485 (in the else):
Hi Bjorn,
It is weird I get a “Uncaught ReferenceError: category is not defined” when I try to implement the filter thing…
Could you please advise what I could do to resolve that error ?
Thanks in advance,
J.
(PS : I also sent you a direct mail through your contact form regarding a paid mission, did you get it ?)
I am also interested to add this feature -category
If you have sorted this out, will be happy to hear some details…
Cheers
Alex
Hello Alex, have you been able to add a dropdown with categories?
I’ll start right now with my attempt, but if you have done something and want to share, it would be amazing 🙂
I’ll try to follow Bjorn’s solution and come back with my comments.
Thank you!
I got it working! Bjorn instructions were quite clear, although I’ve found that something was missing.
I’ll explain what I needed and then how I solved it.
I needed to add a dropdown menu with languages (my categories), so the visitor would be searching by “Address” as well as “Language”. This is what I did:
1. Ensure that my XML data included the language info (I’m creating the XML dynamically when someone adds/modify Interpreters).
2. Add the form field to the form and ensure you provide an ID to it.
3. Within the “jquery.storelocator.js” file, in the settings function (line 8), add the ID of the category field you just added. <- this step was missing from Bjorn's explanation.
4. After these steps, follow Bjorn steps from above, and you should be able to filter by category.
Let me know if I can help you.
Sorry, it’s not working…the zip code I tested it happened to have mainly Spanish interpreters…it wasn’t filtering.
Hello Bjorn, I’m not able to get it to filter by the Category…I’m missing something.
I get “ReferenceError: distance is not defined”.
Here is the code I modified, maybe you can help me a bit.
Thank you!
http://pastebin.com/QB3C49Qj
Hi Bjorn,
We have dealers in the Netherlands and in Belgium.
Google maps i put on NL.
But when i search with a Belgium zip code “8550”. he shows Bulgaria.
Do you have an solution for this.
Thanks,
Laura
Region biasing only seems to accept one parameter: https://developers.google.com/maps/documentation/geocoding/#RegionCodes
Other than using some other service for Geocoding or a back-end geolocation based on IP address, I think what you’ve got up now with B-xxxx is probably the easiest solution. You could also have a country drop down in the form and change the region in the URL based on what the user chooses.
I’m looking into the other question you asked.
Hi there Bjorn,
A great plugin – really got me out of a bind!
I copied the code from the working demo.html file (which is working perfectly – I haven’t changed anything yet as I am just testing options) into a page that has two other forms on it (a search form and mailing list sign up) and even though those two formsa have separate ids etc etc the plugin won’t work if there are other forms on the page – any reason for this??
Thank you
Jan
Do you have any errors that are being displayed in developer tools or a link with an example?
Hi Bjorn,
Thanks for a great plugin but being only able to include a maximum of 26 markers is a big drawback.
It would be better if it used numbers instead of letters.
There is no limit as of 4 versions ago.
Hello. Thank you very much for sharing your work with us, this is an amazing plug in that safes a lot of time to a lot of people, like me. So, sincerely, many many thanks.
Hi again.
I’m doing that the lng and lat values aren’t mandatory in the xml locations file. Because we can get it from google, having the complete address of each store, so i don’t want to make may users search and write the lng and lat values for each store.
I have it working, but with one problem. It works wen my browser haves the xml file cached. But the first time, when it’s not cached, my stores are going to the ocean 🙂
This is my code:
//Process XML
$(data).find(‘marker’).each(function(){
var name = $(this).attr(‘name’);
var lat = $(this).attr(‘lat’);
var lng = $(this).attr(‘lng’);
var address = $(this).attr(‘address’);
var address2 = $(this).attr(‘address2’);
var city = $(this).attr(‘city’);
var state = $(this).attr(‘state’);
var postal = $(this).attr(‘postal’);
var phone = $(this).attr(‘phone’);
var web = $(this).attr(‘web’);
web = web.replace(“http://”,””);
var hours1 = $(this).attr(‘hours1’);
var hours2 = $(this).attr(‘hours2’);
var hours3 = $(this).attr(‘hours3’);
var category = $(this).attr(‘category’);
if (lat==null || lng==null || lat==”” || lng==””)
{
geocoder = new google.maps.Geocoder();
geocoder.geocode( { ‘address’: address + ‘ ‘ + address2 + ‘ ‘ + postal + ‘ ‘ + city}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lng = results[0].geometry.location.lng();
}
});
}
I’m not sure, I think that the callback function for geocoder.geocode function is being slow the first time, and so the process is continuing with lat and lng variables with null values.
How can i make this geocoder.geocode call to block the process until it has get the response?
Sure it’s easy, but i’m not very used to jquery, and i don’t know exactly how to get it.
And i think this is a pretty easy and useful improvement you could add to the plug in 🙂
Kind regards
Ok, don’t waste time about that. This is not possible because when you have several stores Google API returns error “over query limit”. So lng and lat coordinates are needed in the xml locations file for the plugin to work well.
But i don’t want my users to find and configure the lng and lat coordinates for each store. So I think the best idea is to have a function at server side that find out the coordinates automatically using the address filled by the user.
I wrote a C# (asp.net) function to do this, with a little (lot of 🙂 ) help from some webs I found. Here is the function, for anyone who needs it:
————————–
using System;
using System.Xml;
using System.Threading;
using System.Web;
————————–
public static string GetLongLatFromAddress(string address, out string longitude, out string latitude)
{
longitude = “”;
latitude = “”;
XmlDocument doc = new XmlDocument();
try
{
doc.Load(“http://maps.googleapis.com/maps/api/geocode/xml?address=” + HttpUtility.UrlEncode(address) + “&sensor=false”);
XmlNode element = doc.SelectSingleNode(“//GeocodeResponse/status”);
if (element.InnerText == “ZERO_RESULTS”)
{
return (“No data available for the specified location”);
}
else if (element.InnerText == “OVER_QUERY_LIMIT”)
{
Thread.Sleep(200);
return GetLongLatFromAddress(address, out longitude, out latitude);
}
else
{
element = doc.SelectSingleNode(“//GeocodeResponse/result/geometry/location/lat”);
latitude = element.InnerText;
element = doc.SelectSingleNode(“//GeocodeResponse/result/geometry/location/lng”);
longitude = element.InnerText;
return “”;
}
}
catch (Exception ex)
{
return (“(Address lookup failed: ) ” + ex.Message);
}
}
————–
This function gets the coordinates from the Google API URL. With the added that if it gets the over query limit error it waits some time and retry the query.
Hope it helps.
Kind regards, and thanks for your wonderful work Bjorn.
Yeah, the limits are the reason I don’t include Geocoding with the data. Careful when using this class though – the limit is 2,500 requests per day and if you are consistently exceeding that they can block you:
“If you exceed the 24-hour limit or otherwise abuse the service, the Geocoding API may stop working for you temporarily. If you continue to exceed this limit, your access to the Geocoding API may be blocked.”
https://developers.google.com/maps/documentation/geocoding/#Limits
Hi Manwithnoname,
I’m interested in using your code but I’m not familiar with C#. What do I need to do to make your code work?
Rgds,
CJ
Yes like me ! have a solution ?
thanks
Hi Borjn
Will this plugin work with jquery mobile?
Can I also change the markers to custom markers like google store locator.
Joseph
Hi Bjorn
Followed this and seems to work and happy https://www.bjornblog.com/web/jquery-store-locator-plugin#comment-4050
Saw another post where to see if I can have multiple markers, if that works, then I will be more a happy boy.
Hello Borjn,
Thanks for such a fantastic tool and for sharing it!
Any chance the plugin could get it’s data feed from an array within the rendered page itself? I use a content management system called Adobe Business Catalyst. If I could adapt your plugin for use with BC, my clients could update what BC refers to as a web app to feed the “locations” output to the array when the page loads. I could make the data output by the CMS into the array mirror the layout of the XML feed as an example.
Thanks again for the fantastic plug in.
What would the file type of the output be?
Fantastic plugin! Also runs flawlessly in an iframe.
I’d like to know if it is possible to add an email address field to the XML so that it gets interpreted as a mailto: so that when users click on it, it takes them to their default email client.
If you’re not using all the location attributes, such as hours2 or hours3, you could use one of those for an email address. Then, in the template files (in the /templates directory) you could do something like this:
Otherwise, it’s kind of a process of adding a new attribute and passing it through to the correct places. Email makes a lot of sense though. I’ll add that to my list for a future version.
Thanks Bjorn,
I actually tried this before I posted here. I created an email=”email@address.com” field in locations.xml and defined the email display in template files same as per your instructions above, but the email address does not show.
Any other suggestions?
I noticed that to add variables the jquery.storelocator.js needs to be modified. I hacked at it but failed to make it work. Thus when you get a chance please have a look at it and add an email field. As you said, email would be pretty useful.
Borjn
it seems I just added if else statement and used the category instead of creating a type variable to load different type of markers. So so far I have two types of markers on my map for different stores.
Now to tackle infoWindow and see if I can skin it for Jquery mobile.
Any hints direction on handling infoWindows other than reading comments above.
As far as I know the infoWindows can’t be styled without an extra plugin. The InfoBubble library on the following page is one of the only things I’ve seen that allows you to do it (bottom of the list).
https://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries
Borjn
please do not say about the info window.
Hope it can be done this way.
I don’t understand your reply. Please see the details on the following pages. This extension allows you to use CSS3 for the infowindows.
https://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries#InfoBubble
Example:
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html
Bjorn
I think that is the example I am looking for.
I will try and let you know. Thanks for the response.
Hi Borjn
Not sure if this is a bug or not, when I change storeLimit to 50 in the javascript file, it seems to lose my custom marker settings.
Can I go over the 26 limit and still keep my custom markers
sorry index3.html shows my custom markers. As I said once I go over 26 seems to lose my markers and reverts back to default markers.
Borjn
Resolved the issue. Could my posts with my urls get blanked out or deleted please.
Sure. Sorry i couldn’t get back to you earlier. Glad you got it figured out.
Hi Bjorn,
I see in a post above that you may add geocoding to all the addresses in the future, not just the user’s address/location. Have you by chance done this?
You’re better at JS than I, so if not, would you consider it?
Thanks,
Gary.
How many locations will there be? For regular users the documentation states it’s 2,500 geolcation requests per day:
https://developers.google.com/maps/documentation/geocoding/#Limits
Only 30-40 at any one time. I checked the usage & don’t think the limits will be an issue. If it becomes one I will have a good argument for converting it to a business account.
What I have eventualy done is calculate the lng and lat coordinates only once (when user creates the store in my cms) and save it in the database, along with the address, city, …
So my users don’t have to find out coordinates, it’s made by the cms with that asp.net function i posted and then saved in the data base.
This way it’s only one query one time, so it makes no problems with Google API limits 🙂
Thanks @ManWithNoName, I appreciate the insight. Normally I would follow the same path, but in this case the CMS is a closed ERP system, which doesn’t even offer the lat/long fields. I can get names, addresses & phone numbers, but that’s about it.
Bjorn: any thoughts on adding the geocoding option to all the addresses?
Thanks,
Gary.
Hi Bjorn
I want to explain to problems i had using the plugin with asp.net. Maybe you would want to solve it for next version.
The problem is about having more textbox and buttons in the same page. If you want to have buttons that make postback in the same page the store locator is, you need 2 changes:
1. Name and id of the button cannot be “submit”, because it causes an error on postbacks. Just an asp.net restriction. If you do so, you get an error on postback on line theForm.submit(); of asp.net javascript function __doPostBack(eventTarget, eventArgument).
So i changed to:
2. The keyup event is attached to document, so all postbacks make with an enter key launch the store finder button event, and since the textbox use to be blank, then the blankInputAlert appears.
This should be changed, like this:
//ASP.net or regular submission?
if(settings.noForm === true){
$(document).on(‘click.’+prefix, ‘#’ + settings.formContainerDiv + ‘ #btsubmit’, function(e){
get_form_values(e);
});
$(document).on(‘keyup.’+prefix, ‘#’ + settings.formContainerDiv + ‘ #’ + settings.inputID, function(e){
if (e.keyCode === 13) {
get_form_values(e);
}
});
}
Hope it helps. Regards 🙂
Ups, no html allowed. I meant, i changed the button to:
input type=”image” id=”btsubmit” name=”btsubmit” src=”images/submit.jpg” alt=”Submit”
Bjorn,
I just have read all the comments but didn’t find an answer!
How can i rezise the map? Someone?
The map is set up to stretch to the size of the div with the id of “map.” If you look at the CSS file you’d want to change #map-container and #map.
Hi Bjorn!
Very useful plugin, really liked it. I am trying to embed it but I got few questions to ask since I’m not into this jquery.
First of all, I tried to set my default opening map (or center location) but I couldn’t make it.
Or maybe I want to by-pass this zip-code locator. I just want to center the map on a city that I’m going to use and put some places to pin.
Could you please help me?
I think the best way to do that would be to use the defaultLoc option and also set the zoomLevel option to 0. Use the default location example to get you started. Example:
Hi Bjorn, first of all thank you for your interest.
I tried your suggestion but when i add zoomLevel to that line, it wants an input(zip or address) and It doesn’t work even I give zipcode info.
I’ll just use defaultLoc example, but It would be awesome if I could arrange that zoomLevel.
Best regards,
kiv
Hi Bjorn,
I’ve used the defaultLoc exactly as you’ve shown above, but it’s showing all the locations mapped on there too (well, up to 26 of them) – almost as if fullMapStart is set to true (which it isn’t).
Ideally I was hoping for a zoomed out UK map on entry to the page, without any locations mapped.
Regards,
Mark.
Thanks Bjorn,
I’ve found it. Just still one question.
How can i handle the error ZERO_RESULT, i want to display some other text.
That’s an error from Google and it’s not something you can change. Have you set up the data file with all the locations?
Hi, first of all sorry about my bad English
I’m using this wonderful plugin in a furniture website, so it will list the affiliates of this company.
However i would like to know if there’s anyway when i select a city shows in the div “listDiv” just he affiliates that belong to this city and not the others.
Eg. (like is in yout demo):
I select the city Plymouth, in div “listDiv” he shows just the affiliates that belong to Plymouth, and hide the others (like the affiliates in city Edina).
I don’t know if you understand,
Hope you help me, please!!!
I think I understand what you are trying to do and I think it might be best to have a drop-down select field with the main cities. If you follow the example that I posted in the discussion with Devin above it should be very similar:
https://www.bjornblog.com/web/jquery-store-locator-plugin#comment-15026
Ok, i’ll try this and tell you if it works!
Thank you very much
Hey.. this plugin is awesome – really simplifies the painful job of working with Google Maps!
I’m having one small problem where everything looks/works great, but infoWindows don’t show onClick.. no error appears in the console.
Any ideas/thoughts greatly appreciated!
What version of jQuery are you running and do you have an example link?
hey Bjorn,
i know some people have asked this question before … can you post an example of how to push results to another page or did you do it already and I missed it?
Thanks in advance
Again, I don’t understand the point of doing this when you’re using jQuery but I’ve created an example to get people started if they really want to. Open Firebug or Chrome developer tools and go to: http://bjornblog.com/storelocator/querystring-example.html
The first HTML page has some jQuery to add the query string to the URL and the second HTML file has some JS to get the query string value. I just threw a console.log in to show how to use it. When using it with the plugin I’d set the value to a variable and modify the code inside the “else” on line 314 (assuming you’re not using a ASP.net CMS) – if the variable is set geocode the value and then begin mapping, otherwise do the normal functionality. Something like:
WHere do I have to put the code in order to take the address in the URL parameter? In which line?
I tried and it doesn´t work.
Hi Bjorn!
You did an excellent job with the plugin!
I am working on a phonegap project and i decited to use your plugin. The pluging works great on iPhone, but not on android. On android when i try to write in the text area and send the address with the button a white screen pops up and the whole plugin collaps. Have you got any idea what could cose this problem ? I am useing jQuerymobile framework and Adobe phonegap build.
Hmm… are there any errors to work from? I’d start by making sure the templates are loading – is there maybe something different with the paths?
Hey Bjorn, is there anyway I can include GET variables in the location.xml file? What I am doing is generating my XML file via PHP. I renamed the file gen_default_map.php and what I need to do is pass the users current coordinates into the url so that I can query the mySQL database to get the closest business within a 30-mile radius. The problem is with the way the script is written. I can’t simply inject the user’s Geolocated coordinates.
I’d like the URL to read something like this: data/gen_default_map.php?lat=34.383747&lng=-82.364574&radius=30
Here is the code I have written to get the user’s coordinates, and if it can’t generate the coordinates, the PHP file defaults to a particular location.
———————————————————
var LocationGlobal;
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
var lat = position.coords.latitude;
var lon = position.coords.longitude;
LocationGlobal = ‘data/gen_default_map.php?lat=’ + lat + ‘&lng=’ + lon + ‘&radius=100’;
alert(LocationGlobal); // Sets correctly here
});
} else {
console.log(‘Error getting coordinates.’);
}
// alert(LocationGlobal); // Undefined here
———————————————-
How can I write your code to make it generate the user’s geolocated coordinates in the xml file?
Sorry for the late reply, I’m a little confused by your post but I think I understand what you are trying to do. If you want to just feed in the lat/lng from a query string parameter you could use some javascript to get the query string values and then edit line 270 to 281 to something like the following (make sure to set olat and olng). The origin address is needed for the direction links.
My application is one where there are many store locations (franchises) within close proximity. The problem arises when a customer is searching for a store within a specific city name or specific zip code, and instead the function returns the closest store, even though there are matches within the requested city or zip code. I assume this is because the plugin geocodes the user-specified location, which is some form of center of the city or zip code, and then orders the return data by proximity to that location. Because different franchisees own and promote their businesses, when a user searches for the store in CityA, the CityA franchisee is more than a little angry when CityB’s store shows up first in the list. In fact, there are many cases where NO search will yield CityA’s store as the first in a list, because CityA is further from the located center of any zip code or city. Do you have any provision for correcting this? It would be nice of exact matches to the searched city or zip code came first, regardless of calculated distance.
I understand what you mean but how would the locations be sorted if, for example, you wanted to display all the locations within 1 zip code? As far as I know, when you geocode a zip code the latitude and longitude point will be the center of the zip code area. Unless there is a more accurate starting location there would need to be some kind of alternative sorting method. The easiest solution would be to have the input field label set to just “street address.” The plugin currently sorts by only the distance.
Ok, I don’t know if it’s normal, but when you put the autoGeocode:true… you can’t put maxDistance:true. I want to be able to get the Geo location when you first arrive on the page and then you can search with a max distance… Is there a way to do that?
The only thing I found is to put this line:
var maxDistance = settings.distanceAlert;
after the line 486. That way it define the variable with the maxDistanceAlert settings…
Do you have an other way to do this?
Thanks
I wouldn’t really recommend doing this. With the autogeocode option turned on, it starts processing immediately after you agree to share your location. If you stopped it after that, it would just be another step that the user would have to take. I could see if I could make it work so that the user could change the max distance after after everything has processed but I don’t really see a good reason for doing it.