bjorn2404 / jQuery-Store-Locator-Plugin

A store locator plugin using Google Maps API version 3
MIT License
495 stars 235 forks source link

maxDistance and querystringParams not working correctly #151

Closed augustbend closed 8 years ago

augustbend commented 8 years ago

I have created this sample for you to test:

UC 1: Using a search from outside the map page

  1. Open https://dl.dropboxusercontent.com/u/13077873/website/index.html
  2. Enter Glasgow in the field and click Go Result: The user is redirected to the map page but no map is shown. The console says "jquery.storelocator.js:2146 Uncaught Error: No locations found. Please check the dataLocation setting and path." but the locations file is set up correctly.
  3. Then, enter Glasgow in the current page and click Submit. Result: No message, no console error.
  4. Now enter London in the current page and click Submit. Result: The map loads and there are messages from the app.
  5. Then enter Glasgow again in the search field and click Submit. Result: The maps loads and there are messages from the app. As I see, the correct functionality would be to always show the place from the query string and if there are no stores nearby (10/50 miles), always show a message as sometimes happens.
cfxd commented 8 years ago

@bjorn2404 Thank you for such an outstanding library! It really is the bees' knees.

I'm experiencing a similar issue and I've put my code on a temp server so you can see what I'm working with: https://goo.gl/GIObpM. I would appreciate any help on this issue.

This is how I'm calling the library:

if('undefined' !== typeof(local)) {
  $('#bh-sl-map-container').storeLocator({
    'autoComplete':              true,
    'dataRaw':                   local.locations,
    'fullMapStart':              true,
    'infowindowTemplatePath':    local.theme_dir + '/templates/locations/infowindow-description.html',
    'listTemplatePath':          local.theme_dir + '/templates/locations/location-list-description.html',
    'maxDistance':               true,
    'mapSettings': {
                           zoom: 8,
                      mapTypeId: google.maps.MapTypeId.ROADMAP,
                    scrollwheel: false
    },
    'querystringParams':         true,
    'slideMap':                  false
  });
}

The locations referenced is a localized JSON object containing all the markers.

The unexpected behavior occurs when a search from my home page includes a ZIP without any markers. Visitors arrive on the results page with the correct query string parameters but the map never displays, no error pops up, and a console error displays Uncaught Error: No locations found. Please check the dataLocation setting and path.

Removing maxDistance from my JS leads to no more errors and actually exhibits the behavior I want when a ZIP with nor markers is searched on my home page—that is, the error popup displays and all markers display on the map. The obvious downside with this fix is that the distance radius is ignored.

Quick breakdown:

WITHOUT maxDistance

  1. Start on home page
    • JS with querystringParams and hidden <input> setting bh-sl-maxdistance = 60
    • JS without maxDistance
  2. Search 33322
    • Result: displays all markers starting from the closest to the search ZIP.
  3. Search 90210
    • Result: error popup and map displays all markers

WITH maxDistance

  1. Start on home page
    • JS with querystringParams and hidden <input> setting bh-sl-maxdistance = 60 and maxDistance: true
  2. Search 33322
    • Result: displays all markers in search distance starting from the closest to the search ZIP.
    • Change search radius on results: adjusts map results accordingly.
  3. Search 90210
    • Expected result: error popup and map displays all markers
    • Actual result/issue: NO error popup and NO map; console error Uncaught Error: No locations found. Please check the dataLocation setting and path.; all searches fail after this first failure.

My server is setup with maxDistance: true to replicate the error.

Thank you for any help with this!

bjorn2404 commented 8 years ago

This is looking like a one line fix. If you need an immediate fix: search for the "Check the closest marker" comment change the second line after that from:

if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) {

to:

if (_this.settings.maxDistance === true && maxDistance) {
bjorn2404 commented 8 years ago

I've implemented this fix in v2.7.0. Let me know if either of you are still running into it. Thanks

vishnuvijayan77 commented 4 years ago

@bjorn2404 I face the same issue when I give fullmapstart as true and i have empty json file. Is there a way where i can show the map without any pins when the stores json is empty?