Für ein Projekt würde ich gerne eine Gmap erstellen, die relativ viele Marker hat. Die Positionen + Texte der Marker kommen aus einer Datenbank (SQL).
Mein derzeitiger Code sieht so aus:
Code: Alles auswählen
<?php
$verbindung = mysql_connect ("localhost",
"root", "")
or die ("keine Verbindung möglich.
Benutzername oder Passwort sind falsch");
mysql_select_db("googlemaps")
or die ("Die Datenbank existiert nicht.");
$abfrage = "SELECT * FROM positions";
$ergebnis = mysql_query($abfrage);
?>
<!-- Body Teil, muss bleiben!-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API Example: Simple Geocoding</title>
<script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAjukfAShPqYVMq-7wT-QPrxSW02BduV7fa4cQ42E4kidB8_FWmxQE-khZXVQ3jI8k2vrxCi4VPaZCKQ" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(48.2296848, 16.3441712), 13);
geocoder = new GClientGeocoder();
}
<!-- Ende Body, es folgen die JS-Schnipsel der DB -->
<?php while($row = mysql_fetch_object($ergebnis))
{
$i = $i + 1;
echo "map.setCenter(new GLatLng($row->position), 13);
var marker$i = new GMarker(new GLatLng($row->position));
map.addOverlay(marker$i);
marker$i.openInfoWindowHtml($row->text); ";
}
echo "} \n";
?>
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<form action="#" onsubmit="showAddress(this.address.value); return false">
<p>
<input type="text" size="60" name="address" value="1600 Amphitheatre Pky, Mountain View, CA" />
<input type="submit" value="Go!" />
</p>
<div id="map_canvas" style="width: 1000px; height: 800px"></div>
</form>
</body>
</html>
Der Output als HTML sieht so aus:
Code: Alles auswählen
<!-- Body Teil, muss bleiben!-->
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API Example: Simple Geocoding</title>
<script src="http://maps.google.com/maps?file=api&v=2.x&key=ABQIAAAAjukfAShPqYVMq-7wT-QPrxSW02BduV7fa4cQ42E4kidB8_FWmxQE-khZXVQ3jI8k2vrxCi4VPaZCKQ" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(48.2296848, 16.3441712), 13);
geocoder = new GClientGeocoder();
}
<!-- Ende Body, es folgen die JS-Schnipsel der DB -->
map.setCenter(new GLatLng(48.2296848, 16.3441712), 13);
var marker1 = new GMarker(new GLatLng(48.2296848, 16.3441712));
map.addOverlay(marker1);
marker1.openInfoWindowHtml(); map.setCenter(new GLatLng(48.2296848, 16.3441713), 13);
var marker2 = new GMarker(new GLatLng(48.2296848, 16.3441713));
map.addOverlay(marker2);
marker2.openInfoWindowHtml(); }
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<form action="#" onsubmit="showAddress(this.address.value); return false">
<p>
<input type="text" size="60" name="address" value="" />
<input type="submit" value="Go!" />
</p>
<div id="map_canvas" style="width: 1000px; height: 800px"></div>
</form>
</body>
</html>
kann mir jemand sagen, wieso ich nur einen Marker bekomme?
