Skip to content

Commit 50cb736

Browse files
committed
Added component filtering for geocoding to better restrict by area, added callbackGeocodeRestrictions callback that allows the componentRestrictions object to be overridden
1 parent ef93d1a commit 50cb736

File tree

6 files changed

+62
-7
lines changed

6 files changed

+62
-7
lines changed

callbacks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ $('#bh-sl-map-container').storeLocator({
3333
| [callbackNotify](callbacks/callback-notification.md) | Notification callback |
3434
| [callbackRegion](callbacks/callback-region.md) | Region callback |
3535
| [callbackFormVals](callbacks/callback-formvals.md) | Form values callback |
36+
| [callbackGeocodeRestrictions](callbacks/callback-geocode-restrictions.md) | Geocoding component restrictions callback |
3637
| [callbackBeforeSend](callbacks/callback-beforesend.md) | Before location data request callback |
3738
| [callbackDirectionsRequest](callbacks/callback-directionsrequest.md) | Directions request callback |
3839
| [callbackCloseDirections](callbacks/callback-closedirections.md) | Close directions callback |
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# callbackGeocodeRestrictions
2+
3+
## Description
4+
5+
Allows the geocoding restrictions object to be overridden. This object gets passed to the [componentRestrictions parameter](https://developers.google.com/maps/documentation/javascript/geocoding#ComponentFiltering)
6+
when geocoding.
7+
8+
## Parameters
9+
10+
| Name | Type | Description |
11+
|---|---|---|
12+
| addressInput | string | User address input |
13+
| searchInput | string | User name search input when using nameSearch setting |
14+
| distance | string | User distance selection when using maxDistance setting |

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.7.5 - 2018-02-11
1+
/*! jQuery Google Maps Store Locator - v2.7.5 - 2018-02-12
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2018 Bjorn Holine; Licensed MIT */
44

@@ -100,6 +100,7 @@
100100
'callbackNotify' : null,
101101
'callbackRegion' : null,
102102
'callbackFormVals' : null,
103+
'callbackGeocodeRestrictions': null,
103104
'callbackBeforeSend' : null,
104105
'callbackSuccess' : null,
105106
'callbackModalOpen' : null,
@@ -1520,6 +1521,7 @@
15201521
this.writeDebug('processForm',arguments);
15211522
var _this = this,
15221523
distance = null,
1524+
geocodeRestrictions = {},
15231525
$addressInput = $('#' + this.settings.addressID),
15241526
$searchInput = $('#' + this.settings.searchID),
15251527
$distanceInput = $('#' + this.settings.maxDistanceID),
@@ -1586,6 +1588,19 @@
15861588
this.settings.callbackFormVals.call(this, addressInput, searchInput, distance, region);
15871589
}
15881590

1591+
// Add component restriction if the region has been set.
1592+
if (typeof region !== 'undefined') {
1593+
geocodeRestrictions = {
1594+
country: region
1595+
};
1596+
}
1597+
1598+
// Component restriction value via callback.
1599+
if (typeof this.settings.callbackGeocodeRestrictions === 'function') {
1600+
// Component restriction override callback
1601+
geocodeRestrictions = this.settings.callbackGeocodeRestrictions.call(this, addressInput, searchInput, distance);
1602+
}
1603+
15891604
if (addressInput === '' && searchInput === '' && this.settings.autoGeocode !== true) {
15901605
this._start();
15911606
}
@@ -1603,7 +1618,11 @@
16031618
}
16041619
else {
16051620
var g = new this.googleGeocode(this);
1606-
g.geocode({'address': addressInput, 'region': region}, function (data) {
1621+
g.geocode({
1622+
address: addressInput,
1623+
componentRestrictions: geocodeRestrictions,
1624+
region: region
1625+
}, function (data) {
16071626
if (data !== null) {
16081627
olat = data.latitude;
16091628
olng = data.longitude;

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

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ filtering.
3939

4040
* Added callbackAutoGeoSuccess callback that fires after the geolocation API returns a successful result.
4141
* Added callbackFormVals callback that fires after the form values have been processed from the form.
42-
* Added callbackNearestLoc that fires when the nearest location is triggered with the openNearest setting.
42+
* Added callbackGeocodeRestrictions callback that allows the componentRestrictions object to be overridden.
43+
* Added callbackNearestLoc callback that fires when the nearest location is triggered with the openNearest setting.
44+
* Added component filtering for geocoding to better restrict by area.
4345
* Added openNearest setting to open/select the nearest location after searching.
4446
* Fixed issue with featuredLocations setting where featured locations at far distances would trigger distance alert.
4547
* Fixed issue with filtering values containing ampersands, which would not display any results - updated filtering regex.

src/js/jquery.storelocator.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
'callbackNotify' : null,
9797
'callbackRegion' : null,
9898
'callbackFormVals' : null,
99+
'callbackGeocodeRestrictions': null,
99100
'callbackBeforeSend' : null,
100101
'callbackSuccess' : null,
101102
'callbackModalOpen' : null,
@@ -1516,6 +1517,7 @@
15161517
this.writeDebug('processForm',arguments);
15171518
var _this = this,
15181519
distance = null,
1520+
geocodeRestrictions = {},
15191521
$addressInput = $('#' + this.settings.addressID),
15201522
$searchInput = $('#' + this.settings.searchID),
15211523
$distanceInput = $('#' + this.settings.maxDistanceID),
@@ -1582,6 +1584,19 @@
15821584
this.settings.callbackFormVals.call(this, addressInput, searchInput, distance, region);
15831585
}
15841586

1587+
// Add component restriction if the region has been set.
1588+
if (typeof region !== 'undefined') {
1589+
geocodeRestrictions = {
1590+
country: region
1591+
};
1592+
}
1593+
1594+
// Component restriction value via callback.
1595+
if (typeof this.settings.callbackGeocodeRestrictions === 'function') {
1596+
// Component restriction override callback
1597+
geocodeRestrictions = this.settings.callbackGeocodeRestrictions.call(this, addressInput, searchInput, distance);
1598+
}
1599+
15851600
if (addressInput === '' && searchInput === '' && this.settings.autoGeocode !== true) {
15861601
this._start();
15871602
}
@@ -1599,7 +1614,11 @@
15991614
}
16001615
else {
16011616
var g = new this.googleGeocode(this);
1602-
g.geocode({'address': addressInput, 'region': region}, function (data) {
1617+
g.geocode({
1618+
address: addressInput,
1619+
componentRestrictions: geocodeRestrictions,
1620+
region: region
1621+
}, function (data) {
16031622
if (data !== null) {
16041623
olat = data.latitude;
16051624
olng = data.longitude;

0 commit comments

Comments
 (0)