I'm using the following code to geocode a supplied address using the Google Maps API. The idea is to geocode the address and pass the lat/long in the form post so that my controller action can utilize it. Unfortunately, this doesn't seem to work as the lat/long aren't submitted with the rest of the form. What am I doing wrong?
$(document).ready(function() {
$("#search_form").submit(function(event) {
var address = $("#searchAddress").val();
if (address != "") {
var geocoder = new GClientGeocoder();
geocoder.getLatLng(
address,
function(point) {
if (point) {
// Found address, populate hidden form fields
$("#searchLatitude").val(point.lat());
$("#searchLongitude").val(point.lng());
}
}
);
}
});
});