2012-04-12 8 views
0

Ich habe einige Code ich zusammen und ich sehe, dass es ein Problem mit ZLat und ZLng sein muss. Ich frage mich, warum es ist, wenn ich zLat und zLng durch tLat und tLng innerhalb meiner for-Schleife ersetze, dann bekomme ich einen Marker, der Sinn macht. Mit zLat und zLng drin bekomme ich keine Marker. Warum würde das passieren?Google Maps APIv3 über die Handhabung mehrerer Marker

P.S. Meine Warnung für zLat und zLng erzeugt etwas, das wie eine korrekte Ausgabe aussieht, aber das darf nicht sein?

// // // // // // // // Ajax returns from PHP 
xmlhttp.onreadystatechange=function() { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    { 
     var obj = $.parseJSON(xmlhttp.responseText); 

     var tLat = getCookie("tLat"); 
     var tLng = getCookie("tLng"); 

     var options = { 
      zoom: 4, 
      center: new google.maps.LatLng(40.7257, -74.0047), 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

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

     // Adding a marker to the map 
     /*var marker = new google.maps.Marker({ 
      position: new google.maps.LatLng(tLat, tLng), 
      map: map, 
      title: 'Click me', 
      icon: 'http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png' 
     });*/ 

     var marker; 

     alert(obj.length); 

     for(var i=0;i<obj.length;i++) { 

      var zLat = String(obj[i].lat); 
      var zLng = String(obj[i].lng); 

      marker = new google.maps.Marker({ 
       position: new google.maps.LatLng(zLat, zLng), 
       map: map, 
       title: 'Click me' 
      }); 

      alert(zLat+','+zLng+','+i); 
     } 


     $('#map').show(); 
    } 
} 
// // // // // // // // 
+0

Warum verwenden Sie die 'String' Methode? Versuchen Sie, diese Methode aus Ihrem Code auszuschließen. – andresf

Antwort

0
// // // // // // // // Ajax returns from PHP 
xmlhttp.onreadystatechange=function() { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    { 
     var obj = $.parseJSON(xmlhttp.responseText); 

     var tLat = getCookie("tLat"); 
     var tLng = getCookie("tLng"); 

     var options = { 
      zoom: 4, 
      center: new google.maps.LatLng(tLat, tLng), 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

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



     var myLatLng = new google.maps.LatLng(parseFloat(obj[0][2]), parseFloat(obj[0][1])); 

     //var marker = new google.maps.Marker({ position: myLatLng, map: map }); 

     var marker; 

     for(var i=0;i<obj.length;i++) { 

      var myLatLng = new google.maps.LatLng(parseFloat(obj[i].lat), parseFloat(obj[i].lng)); 

      var marker = new google.maps.Marker({ position: myLatLng, map: map }); 
     } 

     $('#map').show(); 
    } 
} 
// // // // // // // //