Skip to content

Commit f8af130

Browse files
committed
Merge pull request #26 from brendannee/master
Handle geolocation address field on blur
2 parents 7c1baa8 + 7c8b422 commit f8af130

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

locationpicker.jquery.js

Lines changed: 23 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,27 @@
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+
gmapContext.geodecoder.geocode({'address': address}, function(results, status) {
199+
if(status == google.maps.GeocoderStatus.OK) {
200+
GmUtility.setPosition(gmapContext, results[0].geometry.location, function(context) {
201+
updateInputValues(inputBinding, context);
202+
context.settings.onchanged.apply(gmapContext.domContainer,
203+
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
204+
});
205+
}
206+
});
207+
}
208+
}, 1000);
209+
});
187210
}
188211
if (inputBinding.latitudeInput) {
189212
inputBinding.latitudeInput.on("change", function() {

0 commit comments

Comments
 (0)