Ciao a tutti sono nuovo ed avrei bisogno di una cortesia.
In giro ho trovato questo codice che mi permette di inserire su google maps i maker
Il codice funziona correttamente cioè mi fa vedere i makers sulla mappa ma se cambio solo la tabella nella query non mi fa vedere più la mappa.
Da premettere che le tabella mysql sono identiche.
Come mai secondo voi?
Grazie
In giro ho trovato questo codice che mi permette di inserire su google maps i maker
PHP:
<?php
$conn = mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
mysql_select_db("mattinale") or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Mappa</title>
<style type="text/css">
body { font: normal 15pt Helvetica, Arial; }
#map { width: 850px; height: 700px; border: 5px; padding: 5px; }
</style>
<script src="http://maps.google.com/maps/api/js?key=____________&sensor=false" type="text/javascript"></script>
<script type="text/javascript">
var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/yellow.png",
new google.maps.Size(32, 32), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
<?php
$query = mysql_query("SELECT * FROM moto")or die(mysql_error());
while($row = mysql_fetch_array($query))
{
$cognome= $row['cognome'];
$nome= $row['nome'];
$lat = $row['lat'];
$lng = $row['lng'];
echo("addMarker($lat, $lng, '$cognome.$nome');\n");
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);
}
</script>
</head>
<body onload="initMap()" style="margin:5px; border:5px; padding:5px;">
<div id="map"></div>
</body>
</html>
PHP:
<?php
$conn = mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
mysql_select_db("mattinale") or die(mysql_error());
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title> Mappa</title>
<style type="text/css">
body { font: normal 15pt Helvetica, Arial; }
#map { width: 850px; height: 700px; border: 5px; padding: 5px; }
</style>
<script src="http://maps.google.com/maps/api/js?key=_____________&sensor=false" type="text/javascript"></script>
<script type="text/javascript">
var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/yellow.png",
new google.maps.Size(32, 32), new google.maps.Point(0, 0),
new google.maps.Point(16, 32));
var center = null;
var map = null;
var currentPopup;
var bounds = new google.maps.LatLngBounds();
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: icon,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
map.panTo(center);
currentPopup = null;
});
}
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(0, 0),
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.ZOOM_PAN
}
});
<?php
$query = mysql_query("SELECT * FROM veicoli")or die(mysql_error());
while($row = mysql_fetch_array($query))
{
$cognome= $row['cognome'];
$nome= $row['nome'];
$lat = $row['lat'];
$lng = $row['lng'];
echo("addMarker($lat, $lng, '$cognome.$nome');\n");
}
?>
center = bounds.getCenter();
map.fitBounds(bounds);
}
</script>
</head>
<body onload="initMap()" style="margin:5px; border:5px; padding:5px;">
<div id="map"></div>
</body>
</html>
Come mai secondo voi?
Grazie