2011-11-07 271 views
-2

我一直在搜索各地試圖找到簡單的代碼來添加多個標記到谷歌地圖。我已經將代碼調整爲簡單標記示例,希望它能起作用。我沒有從php代碼中得到任何錯誤,所以我猜測地圖代碼被搞砸了。這裏是我到目前爲止的代碼:谷歌地圖 - 多標記

<script type="text/javascript"> 
    function initialize() { 
    var latlng = new google.maps.LatLng(<? echo $latlonlocation; ?>); 
    var myOptions = { 
     zoom: <? echo $zoom; ?>, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

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

    var circle = new google.maps.Circle({ 
    map: map, 
    radius: <? echo $searchradius; ?> 
    }); 
    circle.bindTo('center', marker, 'position'); 
<? 
$mapcounter = "01"; 
while ($row106 = mysql_fetch_array($r106)) { 
    if ($row106["mna"] == 1 && $row106["mrt"] == 1) { 
     $imagecolor = "yellow"; 
    } elseif ($row106["mna"] == 1 && $row106["mrt"] == 0) { 
     $imagecolor = "darkblue"; 
    } elseif ($row106["mna"] == 0 && $row106["mrt"] == 0) { 
     $imagecolor = "red"; 
    } else { 
     $imagecolor = "red"; 
    } 
    $imagenumber = sprintf("%02d",$mapcounter); 
    echo "var image = 'mapicons/$imagecolor$imagenumber.png';"; 
    echo "var DealerMarker$imagenumber = new google.maps.Marker({"; 
    $lats = $row106["latitude"]; 
    $lons = $row106["longitude"]; 
    echo "position: $lats $lons,"; 
    echo "map: map,"; 
    echo "icon: image"; 
    $mapcounter++; 
    echo "});"; 
} 
?> 

google.maps.event.addDomListener(window, 'load', initialize); 
</script> 

我也嘗試修改});在端把它的內部或陣列循環之外。兩者都沒有工作。在向其添加數組循環之前,確切的代碼使用了靜態變量。任何人都可以讓我朝着正確的方向

+1

這是一個經典的RTFM更換 echo "position: $lats $lons,"; 。 API參考中提供了大量文檔(包括完整示例)。 – vzwick

+0

http://code.google.com/apis/maps/documentation/javascript/examples/icon-complex.html – DesignerGuy

回答

1

嘗試echo "position: new google.maps.LatLng($lats, $lons),"