Im trying to get a google map sample running and connect to a mysql database to get the data to plot points.
Have got xampp running, created a database called gmap1
Created a table called wholocations
Populated this table with a dozen records (with lat/lon spatial information)
Got a google maps key.
Created a map, and trying to read from the database and populate the map with points.
Im not getting a "Could not connect" error but im not getting any points.
The map appears fine.
Using firefox and have got the code from this tutorial.
Cant see what im doing wrong. Perhaps I have my username details wrong, but from what I saw on php.net, I think im right. Can anyone spot where im going wrong?
- Code: Select all
<html>
<head>
<title>Local Issues Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAABbQOcrHd1l2eJ82xX5iKoxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQYD0HysvPaUlb89IVQ-GMGKz0rYQ" type="text/javascript"></script>
</head>
<body>
<p><strong>Local Issues Example</strong></p>
<div id="map" style="width: 800px; height: 600px"></div>
<script type="text/javascript">
//<![CDATA[
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.setCenter(new GLatLng(51.106971, -3.15307617), 8, G_NORMAL_MAP);
// Creates a marker whose info window displays the given number
function createMarker(point, number)
{
var marker = new GMarker(point);
// Show this markers index in the info window when it is clicked
var html = number;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
};
<?php
$link = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_selectdb("gmap1",$link) or die ("Can\'t use dbmapserver : " . mysql_error());
$result = mysql_query("SELECT * FROM wholocations",$link);
if (!$result)
{
echo "no results ";
}
while($row = mysql_fetch_array($result))
{
echo "var point = new GLatLng(" . $row['lat'] . "," . $row['lon'] . ");\n";
echo "var marker = createMarker(point, '" . addslashes($row['description']) . "');\n";
echo "map.addOverlay(marker);\n";
echo "\n";
}
mysql_close($link);
?>
//]]>
</script>
</body>
</html>