Skip to content

Commit aa9d77a

Browse files
committed
#69 added property 'addressFormat'
1 parent 4e8ca65 commit aa9d77a

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

dist/locationpicker.jquery.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jquery-locationpicker - v0.1.13 - 2016-09-13 */
1+
/*! jquery-locationpicker - v0.1.13 - 2016-09-15 */
22
(function($) {
33
function GMapContext(domElement, options) {
44
var _map = new google.maps.Map(domElement, options);
@@ -74,13 +74,23 @@
7474
longitude: lnlg.lng()
7575
};
7676
},
77+
addressByFormat: function(addresses, format) {
78+
var result = null;
79+
for (var i = addresses.length - 1; i >= 0; i--) {
80+
if (addresses[i].types.indexOf(format) >= 0) {
81+
result = addresses[i];
82+
}
83+
}
84+
return result || addresses[0];
85+
},
7786
updateLocationName: function(gmapContext, callback) {
7887
gmapContext.geodecoder.geocode({
7988
latLng: gmapContext.marker.position
8089
}, function(results, status) {
8190
if (status == google.maps.GeocoderStatus.OK && results.length > 0) {
82-
gmapContext.locationName = results[0].formatted_address;
83-
gmapContext.addressComponents = GmUtility.address_component_from_google_geocode(results[0].address_components);
91+
var address = GmUtility.addressByFormat(results, gmapContext.settings.addressFormat);
92+
gmapContext.locationName = address.formatted_address;
93+
gmapContext.addressComponents = GmUtility.address_component_from_google_geocode(address.address_components);
8494
}
8595
if (callback) {
8696
callback.call(this, gmapContext);
@@ -307,6 +317,7 @@
307317
locationName: settings.locationName,
308318
settings: settings,
309319
autocompleteOptions: settings.autocompleteOptions,
320+
addressFormat: settings.addressFormat,
310321
draggable: settings.draggable,
311322
markerIcon: settings.markerIcon,
312323
markerDraggable: settings.markerDraggable,
@@ -369,6 +380,7 @@
369380
enableAutocomplete: false,
370381
enableAutocompleteBlur: false,
371382
autocompleteOptions: null,
383+
addressFormat: "postal_code",
372384
enableReverseGeocode: true,
373385
draggable: true,
374386
onchanged: function(currentLocation, radius, isMarkerDropped) {},

dist/locationpicker.jquery.min.js

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

0 commit comments

Comments
 (0)