1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| <?php require_once('ma connexion'); ?>
<?php
mysql_select_db($database_basec_ddec, $basec_ddec);
$query_coordonnees = "SELECT * FROM coord_france WHERE cp< 1020 and cp<>0 LIMIT 9";
$coordonnees = mysql_query($query_coordonnees, $basec_ddec) or die(mysql_error());
$row_coordonnees = mysql_fetch_assoc($coordonnees);
$totalRows_coordonnees = mysql_num_rows($coordonnees);
/////////////////////
$TableauPhpLat =array();
$TableauPhpLong =array();
do {
$TableauPhpLat[]=$row_coordonnees['lat'];
$TableauPhpLong[]=$row_coordonnees['long'];
} while ($row_coordonnees = mysql_fetch_assoc($coordonnees));
//////////////////////////
function php2js( $php_array, $js_array_name ) {
// contrôle des parametres d'entrée
if( !is_array( $php_array ) ) {
trigger_error( "php2js() => 'array' attendu en parametre 1, '".gettype($array)."' fourni !?!");
return false;
}
if( !is_string( $js_array_name ) ) {
trigger_error( "php2js() => 'string' attendu en parametre 2, '".gettype($array)."' fourni !?!");
return false;
}
// Création du tableau en JS
$script_js = "var $js_array_name = new Array();\n";
// on rempli le tableau JS à partir des valeurs de son homologue PHP
foreach( $php_array as $key => $value ) {
// pouf, on tombe sur une dimension supplementaire
if( is_array($value) ) {
// On va demander la création d'un tableau JS temporaire
$temp = uniqid('temp_'); // on lui choisi un nom bien barbare
$t = php2js( $value, $temp ); // et on creer le script JS
// En cas d'erreur, remonter l'info aux récursions supérieures
if( $t===false ) return false;
// Ajout du script de création du tableau JS temporaire
$script_js.= $t;
// puis on applique ce tableau temporaire à celui en cours de construction
$script_js.= "{$js_array_name}['{$key}'] = {$temp};\n";
}
// Si la clef est un entier, pas de guillemets
elseif( is_int($key) ) $script_js.= "{$js_array_name}[{$key}] = '{$value}';\n";
// sinon avec les guillemets
else $script_js.= "{$js_array_name}['{$key}'] = '{$value}';\n";
}
// Et retourn le script JS
return $script_js;
}
////////////////////////////////////////////////////////
echo php2js($TableauPhpLat,'arrLat');
echo php2js($TableauPhpLong,'arrLong');
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0" />
<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"></script>
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript">
var map = null;
function load()
{
var latlng = new google.maps.LatLng(45.95, 5.35);
var option = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), option);
createMarker(45.95, 5.35, 'lol');
//downloadUrl("airport.xml", function(data) {
//var xml = xmlParse(data);
//var markers = xml.documentElement.getElementsByTagName("marker");
document.getElementById("test").innerHTML = markers.length;
for (var i = 0; i < arrLat.length; i++) {
var info = arrLat[i];
var lat = arrLat[i];
var lon = arrLong[i];
createMarker(lat, lon, info);
bindInfoWindow(marker, map, infoWindow, html);
}
}
function createMarker(lat, lon, info){
var myLatlng = new google.maps.LatLng(lat, lon);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"info",
//icon: "http://google-maps-icons.googlecode.com/files/airport.png"
});
}
</script>
</head>
<body onload="load()">
<div id="map_canvas" style="width:50%; height:50%"></div> |
Partager