Skip to content

Commit 08d3c7f

Browse files
committed
Handle geolocation address field on blur
1 parent 7c1baa8 commit 08d3c7f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

locationpicker.jquery.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@
171171
});
172172
}
173173
if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) {
174+
var blur = false;
174175
gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0));
175176
google.maps.event.addListener(gmapContext.autocomplete, 'place_changed', function() {
177+
blur = false;
176178
var place = gmapContext.autocomplete.getPlace();
177179
if (!place.geometry) {
178180
gmapContext.settings.onlocationnotfound(place.name);
@@ -184,6 +186,28 @@
184186
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
185187
});
186188
});
189+
$(inputBinding.locationNameInput)
190+
.change(function() {
191+
blur = true;
192+
})
193+
.blur(function() {
194+
setTimeout(function() {
195+
var address = $(inputBinding.locationNameInput).val();
196+
if (address.length > 5 && blur) {
197+
blur = false;
198+
var geocoder = new google.maps.Geocoder();
199+
geocoder.geocode({'address': address}, function(results, status) {
200+
if(status == google.maps.GeocoderStatus.OK) {
201+
GmUtility.setPosition(gmapContext, results[0].geometry.location, function(context) {
202+
updateInputValues(inputBinding, context);
203+
context.settings.onchanged.apply(gmapContext.domContainer,
204+
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
205+
});
206+
}
207+
});
208+
}
209+
}, 1000);
210+
});
187211
}
188212
if (inputBinding.latitudeInput) {
189213
inputBinding.latitudeInput.on("change", function() {

0 commit comments

Comments
 (0)