|
1 | | -/*! jquery-locationpicker - v0.1.13 - 2016-09-13 */ |
| 1 | +/*! jquery-locationpicker - v0.1.13 - 2016-09-15 */ |
2 | 2 | (function($) { |
3 | 3 | function GMapContext(domElement, options) { |
4 | 4 | var _map = new google.maps.Map(domElement, options); |
|
74 | 74 | longitude: lnlg.lng() |
75 | 75 | }; |
76 | 76 | }, |
| 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 | + }, |
77 | 86 | updateLocationName: function(gmapContext, callback) { |
78 | 87 | gmapContext.geodecoder.geocode({ |
79 | 88 | latLng: gmapContext.marker.position |
80 | 89 | }, function(results, status) { |
81 | 90 | 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); |
84 | 94 | } |
85 | 95 | if (callback) { |
86 | 96 | callback.call(this, gmapContext); |
|
307 | 317 | locationName: settings.locationName, |
308 | 318 | settings: settings, |
309 | 319 | autocompleteOptions: settings.autocompleteOptions, |
| 320 | + addressFormat: settings.addressFormat, |
310 | 321 | draggable: settings.draggable, |
311 | 322 | markerIcon: settings.markerIcon, |
312 | 323 | markerDraggable: settings.markerDraggable, |
|
369 | 380 | enableAutocomplete: false, |
370 | 381 | enableAutocompleteBlur: false, |
371 | 382 | autocompleteOptions: null, |
| 383 | + addressFormat: "postal_code", |
372 | 384 | enableReverseGeocode: true, |
373 | 385 | draggable: true, |
374 | 386 | onchanged: function(currentLocation, radius, isMarkerDropped) {}, |
|
0 commit comments