Skip to content

Commit 8b647fb

Browse files
committed
#43 added event handler on 'drag' marker
1 parent dda33e8 commit 8b647fb

File tree

4 files changed

+44
-25
lines changed

4 files changed

+44
-25
lines changed

dist/locationpicker.jquery.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,7 @@
6060
gMapContext.map.panTo(location);
6161
this.drawCircle(gMapContext, location, gMapContext.radius, {});
6262
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);
7464
} else {
7565
if (callback) {
7666
callback.call(this, gMapContext);
@@ -83,6 +73,19 @@
8373
longitude: lnlg.lng()
8474
};
8575
},
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+
},
8689
address_component_from_google_geocode: function(address_components) {
8790
var result = {};
8891
for (var i = address_components.length - 1; i >= 0; i--) {
@@ -116,7 +119,7 @@
116119
}
117120
function updateInputValues(inputBinding, gmapContext) {
118121
if (!inputBinding) return;
119-
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
122+
var currentLocation = GmUtility.locationFromLatLng(gmapContext.marker.position);
120123
if (inputBinding.latitudeInput) {
121124
inputBinding.latitudeInput.val(currentLocation.latitude).change();
122125
}
@@ -306,6 +309,12 @@
306309
markerIcon: settings.markerIcon
307310
});
308311
$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+
});
309318
google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
310319
GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context) {
311320
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);

dist/locationpicker.jquery.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)