Last active
October 23, 2015 22:16
-
-
Save deboorn/8d54adbcf99dfd15f196 to your computer and use it in GitHub Desktop.
Store Locator Widget Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="search-form"> | |
<div> | |
<input type="search" name="address" placeholder="Enter Zip" /> | |
<button type="submit">GO</button> | |
</div> | |
</form> | |
<script src="https://code.jquery.com/jquery-1.11.3.min.js" async defer></script> | |
<script src="https://maps.googleapis.com/maps/api/js?key="></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Locator Search Widget Example | |
* @author Store Locator Script http://storelocatorscript.com | |
*/ | |
var Locator = { | |
/** | |
* URL to store locator installation folder | |
*/ | |
url: null, | |
/** | |
* Google geocoder | |
*/ | |
coder: new google.maps.Geocoder(), | |
/** | |
* Geocode address and return results in handler | |
* | |
* @param address | |
* @param handler | |
*/ | |
codeAddress: function (address, handler) { | |
Locator.coder.geocode({'address': address}, function (results, status) { | |
if (status === google.maps.GeocoderStatus.OK) { | |
handler(results[0]); | |
} else { | |
alert(status); | |
} | |
}); | |
}, | |
/** | |
* Geocode form address input value and send geolocatoin to locator search results | |
* | |
* @param e | |
*/ | |
bindSubmit: function (e) { | |
e.preventDefault(); | |
Locator.codeAddress(this.address.value, function (loc) { | |
var action = Locator.url + "/#/?latitude=" + loc.geometry.location.lat() + "&longitude=" + loc.geometry.location.lng() + "&iso2=US&location=" + loc.formatted_address; | |
window.location = action; | |
}); | |
}, | |
/** | |
* Bind from submit to goecoder search results | |
* | |
* @param form | |
* @param url | |
*/ | |
bind: function (form, url) { | |
Locator.url = url; | |
$(form).submit(Locator.bindSubmit); | |
} | |
}; | |
// How to Use | |
// 1. Change locator URL below to your local installation. | |
// 2. Install code above and HTML form code to webpage. | |
Locator.bind('#search-form', 'https://storelocatorscript.com/locator/demo'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Store Locator Widget Example | |
------ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment