I am using the function getAddress() to get the address of the coordinates provided. How do I make sure that the returned value of the function could be echoed in php?
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places&key=yourAPIkey"></script>
<script type="text/javascript">
function GetAddress(lat,lng) {
var lat = parseFloat(lat);
var lng = parseFloat(lng);
var latlng = new google.maps.LatLng(lat, lng);
var geocoder = geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var addr = results[0].formatted_address;
return addr;
}
}
});
}
</script>
<?php
$lng = 103.72;
$lat = 1.34628;
echo "<script type='text/javascript'>",
"GetAddress(",$lat,",",$lng,");",
"</script>";
?>
</html>