Skip to content

Commit 9318afa

Browse files
committed
Merge pull request #28 from brendannee/master
Handle geolocation of address field on blur
2 parents 46e9256 + a339350 commit 9318afa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/locationpicker.jquery.js

Lines changed: 27 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,30 @@
190192
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
191193
});
192194
});
195+
if(gmapContext.settings.enableAutocompleteBlur) {
196+
inputBinding.locationNameInput.on("change", function(e) {
197+
if (!e.originalEvent) { return }
198+
blur = true;
199+
});
200+
inputBinding.locationNameInput.on("blur", function(e) {
201+
if (!e.originalEvent) { return }
202+
setTimeout(function() {
203+
var address = $(inputBinding.locationNameInput).val();
204+
if (address.length > 5 && blur) {
205+
blur = false;
206+
gmapContext.geodecoder.geocode({'address': address}, function(results, status) {
207+
if(status == google.maps.GeocoderStatus.OK && results && results.length) {
208+
GmUtility.setPosition(gmapContext, results[0].geometry.location, function(context) {
209+
updateInputValues(inputBinding, context);
210+
context.settings.onchanged.apply(gmapContext.domContainer,
211+
[GmUtility.locationFromLatLng(context.location), context.radius, false]);
212+
});
213+
}
214+
});
215+
}
216+
}, 1000);
217+
});
218+
}
193219
}
194220
if (inputBinding.latitudeInput) {
195221
inputBinding.latitudeInput.on("change", function(e) {
@@ -369,6 +395,7 @@
369395
locationNameInput: null
370396
},
371397
enableAutocomplete: false,
398+
enableAutocompleteBlur: false,
372399
enableReverseGeocode: true,
373400
draggable: true,
374401
onchanged: function(currentLocation, radius, isMarkerDropped) {},

0 commit comments

Comments
 (0)