mirror of
https://github.com/nikdoof/vapemap.git
synced 2025-12-18 04:09:22 +00:00
31 lines
1017 B
JavaScript
31 lines
1017 B
JavaScript
|
|
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();
|
|
})
|
|
}
|
|
});
|