I've got everything going great up to a certain point. I have a form where users fill out their address in form (separate fields for street, city, state, zipcode). Once they hit submit, on the submit button, I have a series of onClick functions. It consolidates their address fields into one hidden field seperated by commas and spaces (like you would handwrite your address). This works fine. Then once it's consolidated, the next function geocodes the address and returns the latitude and longitude to hidden fields on the form as well. This works too (I think) here is the code where I do that.
function codeAddress1() {
var sAddress = document.form.post_consolidatedAddress1.value;
var storedLatLng;
var lon;
var lat;
var splittingPoint;
var stoppingPoint;
geocoder.geocode( { 'address': sAddress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
document.form.longitude1.value = results[0].geometry.location.lng();
document.form.latitude1.value = results[0].geometry.location.lat();
alert(document.form.latitude1.value);
alert(document.form.longitude1.value);
} else {
alert("Geocode was not successful. Please contact the site webmaster and inform them of the following error: " + status);
}
});
}
At least when it shows me the alerts, it has latitude and longitude in them. Here's my problem arises though: Once I have those values in the hidden field, I need to submit it to a MySQL database to be used for sorting by distance later. I have structured the database so that the the latitude and longitude fields are type FLOAT with lengths of 10,6 (large enough to contain the returned values I've gotten through testing). But when I submit to the database, I never actually get the value, I only get 0.000000. I've tried several methods of making the value posted from the form a float, this currently what I have in my PHP where I get the values to submit:
$latitude1 = floatval($_REQUEST['latitude1']) ;
$longitude1 = floatval($_REQUEST['longitude1']) ;
I've also tried:
$latitude1 = (float) $_REQUEST['latitude1'] ;
$longitude1 = (float) $_REQUEST['longitude1'] ;
Nothing ever works... Can somebody please help?
floatvalor cast it as a float? Have you tried just inserting the values? Also, after usingfloatvalor casting as float, do the variables$latitude1and$longitude1contain the proper value or do they contain0.000000? Do a little debugging to see where the lat/lon values are actually lost and report back. You probably don't have answers b/c the issue isn't necessarily with your Javascript, it's probably in your PHP, but you've posted very little of it here. - Matt