GoogleMapsExample
From I571/ChE531 2007 Class Wiki
<html>
<head>
<title>Where the I573 students are</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAArOAa_mTw0tU3oZz9P4XIWRQkQdC6kUhxhkpt-CE9vKt7Bcx7GhTKL56QIbjxHPKhuOspPQXeTNVw9A" type="text/javascript"></script>
</head>
<body>
<p><strong>Where the I573 students are</strong></p>
<div id="map" style="width: 800px; height: 600px"></div>
<script type="text/javascript">
//<![CDATA[
// Create a new map
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
var geocoder = new GClientGeocoder();
// Function to plot a name and address on the map (including converting to coordinates)
function showAddress(name, address)
{
geocoder.getLatLng(
address,
function(point)
{
if (!point)
{
alert(address + " not found");
}
else
{
map.setCenter(point, 5, G_NORMAL_MAP);
// Create marker
var marker = new GMarker(point);
// Make shown name when clicking on marker
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(name);});
// Add marker to map
map.addOverlay(marker);
}
}
);
}
// Access the database through PHP and plot markers
<?php
$link = mysql_connect("localhost", "root", "123456") or die("Could not connect: " . mysql_error());
$result = mysql_db_query(dwtestphp,"SELECT name,location FROM people;");
if (!$result)
{
echo "no results ";
}
while($row = mysql_fetch_array($result))
{
echo "showAddress(\"" . $row[0] . "\",\"" . $row[1] . "\");\n";
}
mysql_close($link);
?>
//]]>
</script>
</body>
</html>