Rework the Add Store to use clientside geocoding.

This commit is contained in:
2013-04-01 17:17:31 +01:00
parent ec6a2accc3
commit 036d70ce98
5 changed files with 48 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
function get_form_latlng() {
var addr = $('[id$=address1]').val() + ', ' + $('[id$=city]').val() + ', ' + $('[id$=postcode]').val();
console.log('Inputted address: ' + addr);
var gc = new google.maps.Geocoder();
gc.geocode({'address': addr },update_form_latlng);
return false
}
function update_form_latlng(res, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (res.length > 0) {
res = res[0];
console.log('Found location: ' + res.formatted_address);
$('[id$=geo_latitude]').val(res.geometry.location.lat());
$('[id$=geo_longitude]').val(res.geometry.location.lng());
}
$('.form').submit();
} else {
alert('Unable to lookup the location for the address provided. Please check and resubmit.');
}
}
$(document).ready(function(){
if ($('[id$=geo_latitude]') && $('[id$=geo_latitude]').val() == "" ) {
$('.form').submit(function(){
get_form_latlng();
})
}
});