Bueno, bueno... Muchas gracias a todos!!! Especialmente a @quinqui por su incondicional ayuda.
Ya lo he arragleda. Parte de los problemas eran los query. Pero las polyline tampoco estaban bien. Al tener el mismo nombre sólo quedaba la última polyline para el último marker así que les he dado un nombre único. No me ha hecho falta dárselos mediante un array. Si no que simplemente les añadí el contenido de una variable.
Este es el código final de mi mapa:
Código PHP:
Ver original<?php
include('db_login.php');
$connection = mysql_connect($db_host, $db_username, $db_password); if (!$connection){
}
if (!$db_select){
}
?>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false&language=es">
</script>
<script type="text/javascript">
window.onload = function () {
var options = {
zoom: 5,
center: new google.maps.LatLng(40.84706, -2.944336),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), options);
<?php
$query2 = mysql_query("SELECT * FROM airports WHERE icao='$icao'"); ?>
var Airport1 = '<h3 align="center" style="font-family:Arial, Helvetica, sans-serif"><?php echo $icao; ?> - <?php echo $city; ?></h3>';
var image = 'http://i46.tinypic.com/33zbm09.png';
var latLonCenter = new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
marker<?php echo $icao; ?> = new google.maps.Marker({
position: latLonCenter,
map: map,
draggable: false,
icon: image,
title: '<?php echo $icao; ?> - <?php echo $city; ?>',
Airport1: Airport1
});
var infowindow<?php echo $icao; ?> = new google.maps.InfoWindow({
content: Airport1
});
<?php
$query4 = mysql_query("SELECT * FROM routes WHERE `from`='$icao'");
$query5 = mysql_query("SELECT * FROM airports WHERE icao='$destination'"); $latitude_destination = mysql_result($query5, 0, 'latitude'); $longitude_destination = mysql_result($query5, 0, 'longitude'); ?>
var PolyLine<?php echo $destination;?> = new google.maps.Polyline({
strokeColor: "#FF0000",
strokeOpacity: 2.0,
strokeWeight: 2
});
var polyCords<?php echo $destination;?> = [
new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
new google.maps.LatLng(<?php echo $latitude_destination; ?>, <?php echo $longitude_destination; ?>)
];
google.maps.event.addListener(marker<?php echo $icao; ?>, 'click', function() {
PolyLine<?php echo $destination_delete;?>.setMap(null);
<?php } ?>
PolyLine<?php echo $destination;?>.setPath(polyCords<?php echo $destination;?>);
PolyLine<?php echo $destination;?>.setMap(map);
});
google.maps.event.addListener(marker<?php echo $icao; ?>, 'click', function () {
var n = 1;
var infowindow<?php echo $icao; ?> = new google.maps.InfoWindow({
content: "",
maxWidth: 320,
zIndex: n
});
infowindow<?php echo $icao; ?>.setContent(this.Airport1);
infowindow<?php echo $icao; ?>.setZIndex(n++);
infowindow<?php echo $icao; ?>.open(map, marker<?php echo $icao; ?>);
});
<?php } } ?>
}
</script>
</head>
<body>
<center><div id="map_canvas" style="width:850px; height:560px;"></div></center>
</body>