Skip to content

Commit f264516

Browse files
committed
Added bounds and formatted address info from geocoding API to AJAX data parameters
1 parent 213a076 commit f264516

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v2.5.3 - 2016-06-05
1+
/*! jQuery Google Maps Store Locator - v2.5.4 - 2016-06-05
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2016 Bjorn Holine; Licensed MIT */
44

@@ -428,15 +428,26 @@
428428
* @param lat {number} latitude
429429
* @param lng {number} longitude
430430
* @param address {string} street address
431+
* @param geocodeData {object} full Google geocode results object
431432
* @returns {Object} deferred object
432433
*/
433-
_getData: function (lat, lng, address) {
434+
_getData: function (lat, lng, address, geocodeData ) {
434435
this.writeDebug('_getData',arguments);
435-
var _this = this;
436+
var _this = this,
437+
northEast = '',
438+
southWest = '',
439+
formattedAddress = '';
440+
441+
// Define extra geocode result info
442+
if ( typeof geocodeData !== 'undefined' ) {
443+
formattedAddress = geocodeData.formatted_address;
444+
northEast = JSON.stringify( geocodeData.geometry.bounds.getNorthEast() );
445+
southWest = JSON.stringify( geocodeData.geometry.bounds.getSouthWest() );
446+
}
436447

437448
// Before send callback
438449
if (this.settings.callbackBeforeSend) {
439-
this.settings.callbackBeforeSend.call(this, lat, lng, address);
450+
this.settings.callbackBeforeSend.call(this, lat, lng, address, formattedAddress, northEast, southWest);
440451
}
441452

442453
// Raw data
@@ -473,11 +484,14 @@
473484
$.ajax({
474485
type : 'GET',
475486
url : this.settings.dataLocation + (this.settings.dataType === 'jsonp' ? (this.settings.dataLocation.match(/\?/) ? '&' : '?') + 'callback=?' : ''),
476-
// Passing the lat, lng, and address with the AJAX request so they can optionally be used by back-end languages
487+
// Passing the lat, lng, address, formatted address and bounds with the AJAX request so they can optionally be used by back-end languages
477488
data: {
478489
'origLat' : lat,
479490
'origLng' : lng,
480-
'origAddress': address
491+
'origAddress': address,
492+
'formattedAddress': formattedAddress,
493+
'boundsNorthEast' : northEast,
494+
'boundsSouthWest' : southWest
481495
},
482496
dataType : dataTypeRead,
483497
jsonpCallback: (this.settings.dataType === 'jsonp' ? this.settings.callbackJsonp : null)
@@ -616,6 +630,7 @@
616630
var result = {};
617631
result.latitude = results[0].geometry.location.lat();
618632
result.longitude = results[0].geometry.location.lng();
633+
result.geocodeResult = results[0];
619634
callbackFunction(result);
620635
} else {
621636
callbackFunction(null);
@@ -1473,6 +1488,7 @@
14731488
mappingObj.origin = addressInput;
14741489
mappingObj.name = searchInput;
14751490
mappingObj.distance = distance;
1491+
mappingObj.geocodeResult = data.geocodeResult;
14761492
_this.mapping(mappingObj);
14771493
} else {
14781494
// Unable to geocode
@@ -1860,10 +1876,11 @@
18601876
mapping: function (mappingObject) {
18611877
this.writeDebug('mapping',mappingObject);
18621878
var _this = this;
1863-
var orig_lat, orig_lng, origin, originPoint, page;
1879+
var orig_lat, orig_lng, geocodeData, origin, originPoint, page;
18641880
if (!this.isEmptyObject(mappingObject)) {
18651881
orig_lat = mappingObject.lat;
18661882
orig_lng = mappingObject.lng;
1883+
geocodeData = mappingObject.geocodeResult;
18671884
origin = mappingObject.origin;
18681885
page = mappingObject.page;
18691886
}
@@ -1890,7 +1907,7 @@
18901907
}
18911908
else {
18921909
// Do the data request - doing this in mapping so the lat/lng and address can be passed over and used if needed
1893-
dataRequest = _this._getData(olat, olng, origin);
1910+
dataRequest = _this._getData(olat, olng, origin, geocodeData);
18941911
}
18951912
}
18961913

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ filtering.
3737

3838
### Version 2.5.4
3939

40+
* Added bounds and formatted address info from geocoding API to AJAX data parameters.
4041
* Fixed issue with combination of autoGeocode and originMarker settings.
4142
* Merged in pull request from [drcomix](https://github.com/drcomix) that fixed zoom issue with dragSearch setting.
4243
* Switched included remote scripts in example files to https.

src/js/jquery.storelocator.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,26 @@
425425
* @param lat {number} latitude
426426
* @param lng {number} longitude
427427
* @param address {string} street address
428+
* @param geocodeData {object} full Google geocode results object
428429
* @returns {Object} deferred object
429430
*/
430-
_getData: function (lat, lng, address) {
431+
_getData: function (lat, lng, address, geocodeData ) {
431432
this.writeDebug('_getData',arguments);
432-
var _this = this;
433+
var _this = this,
434+
northEast = '',
435+
southWest = '',
436+
formattedAddress = '';
437+
438+
// Define extra geocode result info
439+
if ( typeof geocodeData !== 'undefined' ) {
440+
formattedAddress = geocodeData.formatted_address;
441+
northEast = JSON.stringify( geocodeData.geometry.bounds.getNorthEast() );
442+
southWest = JSON.stringify( geocodeData.geometry.bounds.getSouthWest() );
443+
}
433444

434445
// Before send callback
435446
if (this.settings.callbackBeforeSend) {
436-
this.settings.callbackBeforeSend.call(this, lat, lng, address);
447+
this.settings.callbackBeforeSend.call(this, lat, lng, address, formattedAddress, northEast, southWest);
437448
}
438449

439450
// Raw data
@@ -470,11 +481,14 @@
470481
$.ajax({
471482
type : 'GET',
472483
url : this.settings.dataLocation + (this.settings.dataType === 'jsonp' ? (this.settings.dataLocation.match(/\?/) ? '&' : '?') + 'callback=?' : ''),
473-
// Passing the lat, lng, and address with the AJAX request so they can optionally be used by back-end languages
484+
// Passing the lat, lng, address, formatted address and bounds with the AJAX request so they can optionally be used by back-end languages
474485
data: {
475486
'origLat' : lat,
476487
'origLng' : lng,
477-
'origAddress': address
488+
'origAddress': address,
489+
'formattedAddress': formattedAddress,
490+
'boundsNorthEast' : northEast,
491+
'boundsSouthWest' : southWest
478492
},
479493
dataType : dataTypeRead,
480494
jsonpCallback: (this.settings.dataType === 'jsonp' ? this.settings.callbackJsonp : null)
@@ -613,6 +627,7 @@
613627
var result = {};
614628
result.latitude = results[0].geometry.location.lat();
615629
result.longitude = results[0].geometry.location.lng();
630+
result.geocodeResult = results[0];
616631
callbackFunction(result);
617632
} else {
618633
callbackFunction(null);
@@ -1470,6 +1485,7 @@
14701485
mappingObj.origin = addressInput;
14711486
mappingObj.name = searchInput;
14721487
mappingObj.distance = distance;
1488+
mappingObj.geocodeResult = data.geocodeResult;
14731489
_this.mapping(mappingObj);
14741490
} else {
14751491
// Unable to geocode
@@ -1857,10 +1873,11 @@
18571873
mapping: function (mappingObject) {
18581874
this.writeDebug('mapping',mappingObject);
18591875
var _this = this;
1860-
var orig_lat, orig_lng, origin, originPoint, page;
1876+
var orig_lat, orig_lng, geocodeData, origin, originPoint, page;
18611877
if (!this.isEmptyObject(mappingObject)) {
18621878
orig_lat = mappingObject.lat;
18631879
orig_lng = mappingObject.lng;
1880+
geocodeData = mappingObject.geocodeResult;
18641881
origin = mappingObject.origin;
18651882
page = mappingObject.page;
18661883
}
@@ -1887,7 +1904,7 @@
18871904
}
18881905
else {
18891906
// Do the data request - doing this in mapping so the lat/lng and address can be passed over and used if needed
1890-
dataRequest = _this._getData(olat, olng, origin);
1907+
dataRequest = _this._getData(olat, olng, origin, geocodeData);
18911908
}
18921909
}
18931910

0 commit comments

Comments
 (0)