Determine the Center of the Map by Customer Location in Store Locator

Follow

Overview

By default, Store Locator will show a general map of your region when loaded. You can customize the view of your map to show your customer's current location.

If your customer has location services enabled in their browser, it will show their current location in the center of the map. The map would also include any nearby stores in their area.

To determine the center of the map by customer location, please follow these steps:

  1. From within your Store Locator app, select Settings.

    select settings

  2. Select Display Settings.

    select display settings

  3. Copy and paste this code in the "Page Footer HTML" field:
    <script>
    jQuery(document).ready(function(){
    var map = boldMap
    if (typeof map === 'undefined') {
    return
    }
    var infoWindow = new google.maps.InfoWindow({map: map});
     navigator.geolocation.getCurrentPosition(function(position) {
     var pos = {
     lat: position.coords.latitude,
     lng: position.coords.longitude
     };
    
     infoWindow.setPosition(pos);
     infoWindow.setContent('Location found.');
     map.setCenter(pos);
     jQuery('.search_bar button').click();
     }, function() {
     handleLocationError(true, infoWindow, map.getCenter());
     });
    
     function handleLocationError(browserHasGeolocation, infoWindow, pos) {
     infoWindow.setPosition(pos);
     infoWindow.setContent(browserHasGeolocation ?
     'Error: The Geolocation service failed.' :
     'Error: Your browser doesn\'t support geolocation.');
     }
    });
    </script>

    paste this code in the Page Footer HTML

  4. Select Save.

    Save

0 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.