Skip to content

Commit 6ecda16

Browse files
committed
Handle geolocation address field on blur
1 parent 336fab6 commit 6ecda16

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/locationpicker.jquery.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@
177177
});
178178
}
179179
if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) {
180+
var blur = false;
180181
gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0));
181182
google.maps.event.addListener(gmapContext.autocomplete, 'place_changed', function() {
183+
blur = false;
182184
var place = gmapContext.autocomplete.getPlace();
183185
if (!place.geometry) {
184186
gmapContext.settings.onlocationnotfound(place.name);
@@ -190,6 +192,28 @@
190192
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
191193
});
192194
});
195+
inputBinding.locationNameInput.on("change", function(e) {
196+
if (!e.originalEvent) { return }
197+
blur = true;
198+
});
199+
inputBinding.locationNameInput.on("blur", function(e) {
200+
if (!e.originalEvent) { return }
201+
setTimeout(function() {
202+
var address = $(inputBinding.locationNameInput).val();
203+
if (address.length > 5 && blur) {
204+
blur = false;
205+
gmapContext.geodecoder.geocode({'address': address}, function(results, status) {
206+
if(status == google.maps.GeocoderStatus.OK && results && results.length) {
207+
GmUtility.setPosition(gmapContext, results[0].geometry.location, function(context) {
208+
updateInputValues(inputBinding, context);
209+
context.settings.onchanged.apply(gmapContext.domContainer,
210+
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
211+
});
212+
}
213+
});
214+
}
215+
}, 1000);
216+
});
193217
}
194218
if (inputBinding.latitudeInput) {
195219
inputBinding.latitudeInput.on("change", function(e) {

0 commit comments

Comments
 (0)