Skip to content

Commit 86cca3c

Browse files
committed
Added Google Places autocomplete option and example
1 parent 22685b3 commit 86cca3c

File tree

5 files changed

+76
-3
lines changed

5 files changed

+76
-3
lines changed

dist/assets/js/plugins/storeLocator/jquery.storelocator.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'defaultLoc' : false,
5757
'defaultLat' : null,
5858
'defaultLng' : null,
59+
'autoComplete' : false,
5960
'autoGeocode' : false,
6061
'maxDistance' : false,
6162
'maxDistanceID' : 'bh-sl-maxdistance',
@@ -181,6 +182,16 @@
181182
$('.' + this.settings.overlay).hide();
182183
}
183184

185+
// Set up Google Places autocomplete if it's set to true
186+
if (this.settings.autoComplete === true) {
187+
var _this = this;
188+
var searchInput = document.getElementById(this.settings.addressID);
189+
var autoPlaces = new google.maps.places.Autocomplete(searchInput);
190+
autoPlaces.addListener('place_changed', function(){
191+
_this.processForm(null);
192+
});
193+
}
194+
184195
// Load the templates and continue from there
185196
this._loadTemplates();
186197
},
@@ -487,7 +498,7 @@
487498
var _this = this,
488499
doAutoGeo = this.settings.autoGeocode,
489500
latlng;
490-
501+
491502
// Full map blank start
492503
if (_this.settings.fullMapStartBlank !== false) {
493504
var $mapDiv = $('#' + _this.settings.mapID);

dist/assets/js/plugins/storeLocator/jquery.storelocator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/autocomplete-example.html

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Autocomplete Example</title>
5+
<meta charset="UTF-8">
6+
<link rel="stylesheet" type="text/css" href="assets/css/storelocator.css" />
7+
</head>
8+
9+
<body>
10+
11+
<div class="bh-sl-container">
12+
<div id="page-header">
13+
<h1 class="bh-sl-title">Using Chipotle as an Example</h1>
14+
<p>I used locations around Minneapolis and the southwest suburbs. So, for example, Edina, Plymouth, Eden Prarie, etc. would be good for testing the functionality.
15+
You can use just the city as the address - ex: Edina, MN.</p>
16+
</div>
17+
18+
<div class="bh-sl-form-container">
19+
<form id="bh-sl-user-location" method="post" action="#">
20+
<div class="form-input">
21+
<label for="bh-sl-address">Enter Address or Zip Code:</label>
22+
<input type="text" id="bh-sl-address" name="bh-sl-address" placeholder="" />
23+
</div>
24+
25+
<button id="bh-sl-submit" type="submit">Submit</button>
26+
</form>
27+
</div>
28+
29+
<div id="bh-sl-map-container" class="bh-sl-map-container">
30+
<div id="bh-sl-map" class="bh-sl-map"></div>
31+
<div class="bh-sl-loc-list">
32+
<ul class="list"></ul>
33+
</div>
34+
</div>
35+
</div>
36+
37+
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
38+
<script src="assets/js/libs/handlebars.min.js"></script>
39+
<script src="http://maps.google.com/maps/api/js?libraries=places"></script> <!-- Note the extra query string parameter -->
40+
<script src="assets/js/plugins/storeLocator/jquery.storelocator.js"></script>
41+
<script>
42+
$(function() {
43+
$('#bh-sl-map-container').storeLocator({
44+
'autoComplete': true
45+
});
46+
});
47+
</script>
48+
49+
</body>
50+
</html>

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ filtering.
3838
### Version 2.3.4
3939

4040
* Added new selected marker image options to highlight clicked marker.
41+
* Added Google Places autocomplete option and example.
4142

4243
### Version 2.3.3
4344

src/js/jquery.storelocator.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
'defaultLoc' : false,
5454
'defaultLat' : null,
5555
'defaultLng' : null,
56+
'autoComplete' : false,
5657
'autoGeocode' : false,
5758
'maxDistance' : false,
5859
'maxDistanceID' : 'bh-sl-maxdistance',
@@ -178,6 +179,16 @@
178179
$('.' + this.settings.overlay).hide();
179180
}
180181

182+
// Set up Google Places autocomplete if it's set to true
183+
if (this.settings.autoComplete === true) {
184+
var _this = this;
185+
var searchInput = document.getElementById(this.settings.addressID);
186+
var autoPlaces = new google.maps.places.Autocomplete(searchInput);
187+
autoPlaces.addListener('place_changed', function(){
188+
_this.processForm(null);
189+
});
190+
}
191+
181192
// Load the templates and continue from there
182193
this._loadTemplates();
183194
},
@@ -484,7 +495,7 @@
484495
var _this = this,
485496
doAutoGeo = this.settings.autoGeocode,
486497
latlng;
487-
498+
488499
// Full map blank start
489500
if (_this.settings.fullMapStartBlank !== false) {
490501
var $mapDiv = $('#' + _this.settings.mapID);

0 commit comments

Comments
 (0)