Les archives de FluxBB.fr
Vous n'êtes pas identifié(e).
Pages : 1
Suite à mon forum que j'avais présenté posté ici, je fournis le code source que j'ai développé pour la carte google map que j'ai intégré.
Carte originale voir ici: www.normandie-sansfil.com/forum/map.php
La particularité de la carte est que les données qui sont affichées viennent d'une base mysql, donc la manipulation de ces données est facile.
Code la page principale map.php
<?php
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/map.php';
$page_title = pun_htmlspecialchars($pun_config['o_board_title']." / ".$lang_map['Title']);
require PUN_ROOT.'header.php';
?>
<script src="http://maps.google.com/maps?file=api&v=2&key=votreclé" type="text/javascript"></script>
<script src="map_data.php" type="text/javascript"></script>
<script src="js/map_functions.js" type="text/javascript"></script>
<body>
<div class="box block">
<h2><?php echo $lang_map['Title'] ?></h2>
<div id="map" style=" height: 500px" ><br /><br /><?php echo $lang_map['chargement'] ?>
<noscript><b>Javascript n'est pas activé pour utilisé Google Maps.</b>
However, it seems JavaScript is either disabled or not supported by your browser.
To view Google Maps, enable JavaScript by changing your browser options, and then
try again.
</noscript>
</div>
</div>Fichier map_data.php, permet la récupération des données dans la bdd
<?php
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
require PUN_ROOT.'lang/'.$pun_user['language'].'/map.php';
$relais = $db->query('SELECT `lat`, `long`, `ville`, `etat`, `addr1`, `img1`,`note` FROM `relaiswifi` ORDER BY `ville`') or error('Unable to fetch user list', __FILE__, __LINE__, $db->error());
$joiner1 = '';
?>
var markers = [
<?php while($row1 = mysql_fetch_assoc($relais)): ?>
<?= $joiner1 ?>
{
'latitude': <?= $row1['lat'] ?>,
'longitude': <?= $row1['long'] ?>,
'ville': '<?= addslashes($row1['ville']) ?>',
'etat': <?= $row1['etat'] ?>,
'addr': '<?= addslashes($row1['addr1']) ?>',
'img': '<?= addslashes($row1['img1']) ?>',
<?
$row1['note']=str_replace(CHR(10),"",$row1['note']);
$row1['note']=str_replace(CHR(13),"<br />",$row1['note']);
?>
'notes': '<?= addslashes($row1['note']) ?>'
}
<?
$joiner1 = ',';
?>
<?php endwhile; ?>
];Fichier map_function.js,
var map;
var centerLatitude = 49.102645497788814;
var centerLongitude = -1.0931396484375;
var startZoom = 8;
var gicons = [];
gicons[0] = new GIcon(G_DEFAULT_ICON, "img/marker_actif3.png");
gicons[1] = new GIcon(G_DEFAULT_ICON, "img/marker_actif2.png");
gicons[2] = new GIcon(G_DEFAULT_ICON, "img/marker_actif1.png");
gicons[3] = new GIcon(G_DEFAULT_ICON, "img/marker_actif4.png");
function add_relais(longitude, latitude, ville, etat, addr, img, notes) {
if (addr == "adresse inconnue")
addr="";
else
addr= '<br />' + addr;
if (notes == "*")
notes="";
else
notes= '<br /><br />' + notes;
if (img != "*")
var html = '<strong>' + ville + '</strong>' + addr + '<br /><br />   <a href="img/users/' + img + '"><img height="80" src="img/users/' + img + '"/></a>' + notes;
else
var html = '<strong>' + ville + '</strong>' + addr + notes;
var marker = new GMarker(new GLatLng(latitude, longitude),gicons[etat]);
GEvent.addListener(marker, 'click',
function() {
marker.openInfoWindowHtml(html);
}
);
map.addOverlay(marker);
}
function MyClick(d){
marker2[d].openInfoWindowHtml(html2[d]);
}
function init() {
map = new GMap(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
for(id_ap in markers) {
add_relais(markers[id_ap].longitude, markers[id_ap].latitude, markers[id_ap].ville, markers[id_ap].etat,markers[id_ap].addr,markers[id_ap].img,markers[id_ap].notes);
}
document.getElementById("sidebar").innerHTML = sidebar_html;
}
window.onload = init;J'ai aussi développé un module pour mettre à jour les données contenus dans la base, mais je ne le mets pas car sa relève juste de la simple communications avec une bdd en php
Dernière modification par DeCo (04-03-2007 13:25:39)
Hors ligne
Pages : 1