I am trying to pass the value from javascript to google maps v3. Here i have php code that is getting the lat and lon values from database and generating table for one record.
i am getting lat and lon from that table and alerting that value.Now i want to pass the lat and lon values to the google maps, onclick. how can i do this?
Code:
while($row = mysql_fetch_assoc($retval))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['theater_name'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td id='lat'>" . $row['lat'] . "</td>";
echo "<td id='lon'>" . $row['lon'] . "</td>";
echo "</tr>";
}
The above code is generating the table using php code.
<script type="text/javascript">
function getvalue()
{
var lat = document.getElementById('lat').innerHTML;
var lon = document.getElementById('lon').innerHTML;
alert(lat+","+lon);
}
</script>
The above javascript function is getting the lat and lon value from the table.
Now i want to pass the lat and lon values to the below goole maps api to lat and lon
Code:
<script type="text/javascript">
function initialize() {
var mapDiv = document.getElementById('map-canvas');
var map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(12.955649,77.570837),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
In place of (12.955649,77.570837) i want to get the lat and lon value that the javascript function is getting from table