-4

我想在地图上显示标记,但我只能看到第一个。问题是什么?

而标记没有显示任何

    <?php
 session_start();

 //connessione al DB
 include("dati_db.inc.php");

 mysql_connect($host,$username,$password)or die("Connessione IMPOSSIBILE al DBMS. TIPO ERRORE:".mysql_error());
 mysql_select_db($database)or die("IMPOSSIBILE selezionare il DataBase");


 $idric=$_GET['id_ric']; //id richiesta
 $sql = "SELECT * FROM richieste WHERE id=".$idric;
 $dati=mysql_query($sql);
 if (!$dati) {
    echo "Query non eseguita correttamente sul DB(".$sql."): ".mysql_error();
    exit;
 }

 $row=mysql_fetch_assoc($dati);
 $luogo=$row['luogo'];
 $indirizzo=$row['indirizzo'];
 $descrizione=$row['descrizione'];
 $oggetto=$row['oggetto'];
 $indirizzogoogle=$luogo." , ".$indirizzo;

?>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalableo"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps API v3: geocoding</title>
<style type="text/css">
html, body { margin:0; padding:0; width:100%; height:100%; }
body { background:#FFFFFF; color:#000000; font-family:Arial, Helvetica, sans-serif; font-size:12px; line-height:150%; text-align:center;}
#map { width:100%; height:95%; }
input { width:250px; }
#tooltip { padding:10px; text-align:left; }
#tooltip p { padding:0; margin:0 0 5px 0; }
</style>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=it"></script>
<script type="text/javascript" src="inc/jquery-1.7.2.js"></script>
<script type="text/javascript" src="inc/myjs.js"></script>

<script type="text/javascript">

var createMap = function() {


    //indirizzo ricavato in precedenza del luogo dell'intervento
    var address = "<?php echo ($indirizzogoogle);?>";


    var geocoder = new google.maps.Geocoder();

    geocoder.geocode( {'address': address}, function(results,status) {
        if (status == google.maps.GeocoderStatus.OK) {

            var options = {
                zoom: 12,
                center: results[0].geometry.location,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };  

            var map = new google.maps.Map(document.getElementById('map'), options);

            var marker = new google.maps.Marker(
                {
                position: results[0].geometry.location,
                map: map,
                title: 'punto di intervento'
                }
            );

            var tooltip = '<div id="tooltip">'+
                '<p>Indirizzo punto di intervento<br>'+             
                results[0].formatted_address+'</p>'+
                '</div>';

            var infowindow = new google.maps.InfoWindow({
                content: tooltip
            });

            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(map,marker);
            });


            sedi = new Array();
            dim=0;
            //popoli vettore
            <?php 
                //recupero info di tutte le sedi
                $query="SELECT * FROM utenti WHERE tipo=3";
                $query_sedi=mysql_query($query);

                //per ogni record creiamo un MARKER
                $contcs=mysql_num_rows($query_sedi);

                if($contcs > 0){

                    //se ci sono records mostriamo tutte le sedi in un ciclo
                    while($line = mysql_fetch_array($dati, MYSQL_ASSOC)){
                        //recupero alcune informazioni
                        $sede = $line['sede'];  
                        echo ("cod_indirizzi($sede);\n");           

                    }
                }
                ?>


        } else {
          alert("Problema nella ricerca dell'indirizzo: " + status);
        }

      });
}; 

function cod_indirizzi(indirizzo){
    geocoder.geocode({'address':indirizzo}, function(result, status){
        map.setCenter(result[0].geometry.location);

        var marker= new google.maps.Marker
                    ({map:map,
                        position:result[0].geometry.location,
                        title: indirizzo});
    });
}


window.onload = createMap;
</script>
</head>
<body>

<div id="map"></div>
</body>
</html>

获得的地图只有一个标记,您应该看到 3 错误是什么?

4

1 回答 1

2

这是我做过的类似脚本可以帮助你使用jquery 1.2.6

(function() {
 window.onload = function() 
 {
     var ttl=["place1","place2","place3"];
     var options = {
 zoom: 13,
center: new google.maps.LatLng(28.550000, 77.22496000000001),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options); 
    // Creating an array that will contain the coordinates 
    var places = [];
    places.push(new google.maps.LatLng(28.550392878584265, 77.25169658660889));
    places.push(new google.maps.LatLng(28.546396951091907 , 77.19741940498352));
    places.push(new google.maps.LatLng(28.528748, 77.219663));    
      // Looping through the places array
      for (var i = 0; i < places.length; i++) 
      {
          // Adding the marker as usual
          var marker = new google.maps.Marker({
      position: places[i], 
      map: map,
      title: ttl[i]
      });      
  // Wrapping the event listener inside an anonymous function 
  // that we immediately invoke and passes the variable i to.
     (function(i, marker) {
      // Creating the event listener. It now has access to the values of
      // i and marker as they were during its creation

      google.maps.event.addListener(marker, 'mouseover', function() {
      var infowindow = new google.maps.InfoWindow({
      content: '<div style="overflow:hidden;">'+ttl[i]+'</div>'
      });           
      infowindow.open(map, marker);
      setTimeout(function () { infowindow.close(); }, 5000);  
     });      
})(i, marker);
   }
   }
   })();

HTML

    <div id="map"></div>

CSS

#map {
width: 400px;
height: 400px;
border: 4px solid #ccc;
}
于 2012-05-26T02:23:35.603 回答