|
60 | 60 | gMapContext.map.panTo(location); |
61 | 61 | this.drawCircle(gMapContext, location, gMapContext.radius, {}); |
62 | 62 | if (gMapContext.settings.enableReverseGeocode) { |
63 | | - gMapContext.geodecoder.geocode({ |
64 | | - latLng: gMapContext.location |
65 | | - }, function(results, status) { |
66 | | - if (status == google.maps.GeocoderStatus.OK && results.length > 0) { |
67 | | - gMapContext.locationName = results[0].formatted_address; |
68 | | - gMapContext.addressComponents = GmUtility.address_component_from_google_geocode(results[0].address_components); |
69 | | - } |
70 | | - if (callback) { |
71 | | - callback.call(this, gMapContext); |
72 | | - } |
73 | | - }); |
| 63 | + this.updateLocationName(gMapContext, callback); |
74 | 64 | } else { |
75 | 65 | if (callback) { |
76 | 66 | callback.call(this, gMapContext); |
|
83 | 73 | longitude: lnlg.lng() |
84 | 74 | }; |
85 | 75 | }, |
| 76 | + updateLocationName: function(gmapContext, callback) { |
| 77 | + gmapContext.geodecoder.geocode({ |
| 78 | + latLng: gmapContext.marker.position |
| 79 | + }, function(results, status) { |
| 80 | + if (status == google.maps.GeocoderStatus.OK && results.length > 0) { |
| 81 | + gmapContext.locationName = results[0].formatted_address; |
| 82 | + gmapContext.addressComponents = GmUtility.address_component_from_google_geocode(results[0].address_components); |
| 83 | + } |
| 84 | + if (callback) { |
| 85 | + callback.call(this, gmapContext); |
| 86 | + } |
| 87 | + }); |
| 88 | + }, |
86 | 89 | address_component_from_google_geocode: function(address_components) { |
87 | 90 | var result = {}; |
88 | 91 | for (var i = address_components.length - 1; i >= 0; i--) { |
|
116 | 119 | } |
117 | 120 | function updateInputValues(inputBinding, gmapContext) { |
118 | 121 | if (!inputBinding) return; |
119 | | - var currentLocation = GmUtility.locationFromLatLng(gmapContext.location); |
| 122 | + var currentLocation = GmUtility.locationFromLatLng(gmapContext.marker.position); |
120 | 123 | if (inputBinding.latitudeInput) { |
121 | 124 | inputBinding.latitudeInput.val(currentLocation.latitude).change(); |
122 | 125 | } |
|
306 | 309 | markerIcon: settings.markerIcon |
307 | 310 | }); |
308 | 311 | $target.data("locationpicker", gmapContext); |
| 312 | + google.maps.event.addListener(gmapContext.marker, "drag", function(event) { |
| 313 | + updateInputValues(gmapContext.settings.inputBinding, gmapContext); |
| 314 | + if (gmapContext.settings.inputBinding.locationNameInput) { |
| 315 | + GmUtility.updateLocationName(gmapContext); |
| 316 | + } |
| 317 | + }); |
309 | 318 | google.maps.event.addListener(gmapContext.marker, "dragend", function(event) { |
310 | 319 | GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context) { |
311 | 320 | var currentLocation = GmUtility.locationFromLatLng(gmapContext.location); |
|
0 commit comments