I have this module up and working beautifully. I would love to be able to have a single textfield form in a block or within a node that would POST to the store locator page.

Is this doable?

Comments

PMorris’s picture

I'd like to do this too. I'm looking to make a block on my homepage with a search field linking to the store locator landing page. It would be nice to be able to add a big "Go" or "search" button instead of just hitting return to activate search too!

Hope this doesn't sound too much like a 'me too' post but I just want to show there is a demand for it.

lquessenberry’s picture

I would also like to do this. I am looking for a solution to this and will try to post back asap.

PMorris’s picture

I found you can do this with the Open layers locator module. It's a bit more complicated to set up but it works. See this thread:

https://drupal.org/node/2110239#comment-7967895

lquessenberry’s picture

I have installed the Google Store Locator module and imported several stores. I am wondering if there is a way to do something similar here that allows for the same functionality. I just got used to this module, and I would have to reconfigure a lot of modules and settings to use Open Layers Locator.

sui_page’s picture

I too am looking for a kind of block for the Google store locator. I was able to generate a half decent vesion of it, see here.

About halfway through the page you'll see the 'Find an Envirobank' form. While it does auto-search for locations after submitting you are directed to the 'Locator' page and then you have to re-insert the location for it to work.

Is there any way I can have this automatically search once it redirects to the 'Locator' page?

Ganganation’s picture

Here are my first thoughts to this request. I've already got it working that I can retrieve GET data from the url and show my location on the map.
I know there are better ways to do this. But it is not yet finished.

First of all I add these lines in google_store_locator.module on line 313:

    'test_js' => array(
      '#attached' => array(
        'js' => array(drupal_get_path('module', 'google_store_locator') . '/js/google_store_locator_get_name.js'),
      ),
    ),

After that I created a new js file called google_store_locator_get_name in the directory js. This is the code:

(function ($) {

  window.onload = function() {
    // Get location from GET
    url = location.href;
    var locationName = url.substring(url.indexOf('?'));
    locationName = locationName.replace('?', '');

    // Create lat long from locationName (or postal code)
    geocoder = new google.maps.Geocoder();
    codeAddress(locationName);
    
    // & send it to input field
    $('#google-store-locator-map-container .location-search input').val(locationName);

    return false;
  };

  function codeAddress(address) {
    geocoder.geocode( { 'address': address}, function(results, status) {

      if (status == google.maps.GeocoderStatus.OK) {
        var lat = results[0].geometry.location.lat()
        var lng = results[0].geometry.location.lng()

        var position = [lat, lng];

        positionSuccess(position);
      } else {
        alert('Geocode was not successful for the following reason: ' + status);
      }
    });
  }

  /**
   * Success callback if we're able to obtain lat/lng coordinates for a user.
   */
  function positionSuccess(position) {

    // Centre the map on the new location
    var latLng = new google.maps.LatLng(position[0], position[1]);

    Drupal.GSL.currentMap.panTo(latLng);

    // Get zoom level from settings
    var zoom = Drupal.settings.gsl[Drupal.GSL.currentMap.mapid].mapzoom;

    Drupal.GSL.currentMap.setZoom(zoom);

    var marker = new google.maps.Marker({
      map: Drupal.GSL.currentMap,
      position: latLng,
      title: 'You are here!',
      // Use Google's default blue marker.
      icon: 'http://maps.google.com/mapfiles/ms/icons/blue-dot.png'
    });
  }

})(jQuery);

Please feel free to give your feedback on this. Work still in progress.

There's probably a better approach. For now this works.

myl6858’s picture

Issue summary: View changes

Was someone able to solve this?

brian.seek’s picture

I got the solution from #6 working good enough. Would be nice to combine that with the Location Awareness feature. As it is only one way will work. There are some bugs with the GET location when it first loads. It will focus the map correctly but won't display the nearest stores in the listing area.

eurotrash’s picture

I took a different approach to solving this problem, not as elegant or flexible as #6, it might work for some situations so it is worth mentioning.

I wanted a subset of locations to be available on pages located below the main install. This approach only works because any url segments passed to the default location are ignored by the view, loading a blank map.

First I cloned the default page view, then filtered the results, and changed the url.

PATHS
--------------------------------------------------------------
/store-locator/ -- load all locations, default implementation of the view
/store-locator/group-one -- filtered cloned view, only loads stores form group 1
--------------------------------------------------------------

In the file "google_store_locator.js" around line 49 I added the following code:

 /// load alternate data sources based on url path
 
var pathname = window.location.pathname;
if(pathname == '/store-locator/group-1'){

/// load cloned view path      
      url = '/store-locator/hospitals/json';

 }else{
    
 /// load module defined default 
      url = this._datapath;
  } 

Now you should see a map with a subset of markers at: /store-locator/group-1 . All features appear to work correctly.

phelix’s picture

Nevermind. I looked at an older version of this module and figured out where this info should be added at and it seems to be loading the JS file properly. I would just remove this post to not cloud things up but there is no option to do so.

srikanthgdk_drupal’s picture

How to make the nearest stores working from #6