After a user fills his address in a text field and hits the submit button the address is sent to google maps by javascript which then receives back the coordinates of the address.
I then want to pass the coordinates back to a following PHP code so I can save them to the DB.
So if this is the code under a single PHP file how can this be done?
P.S. Just to be clearer, all of this is done under one PHP function that handles the submitting.
<script type="text/javascript"
...
var lat = results[0].geometry.location.latitude;
var lng = results[0].geometry.location.longitude;
...
}
</script>
<?php
$latitude = ??? ;
$longitude = ??? ;
?>
If you get the lat/long in the page when submit is clicked – before the form is submitted to you your handling PHP script – just store the results in hidden inputs;
<input id="lat" type="hidden" name="lat" value=""/>using js to update their values after you receive them from the API call;
Then allow the form to submit as normal and fetch “
lat” from the query string/post data.