2010-11-11 98 views
1

繼承人的問題,我有一個數據庫,這就是堅持的標記圖像的信息:谷歌地圖V3設置標記大小動態

我正在retreiving所有以Ajax調用和保存數據爲對象,所以我可以檢查標記的位置類型併爲該類型的位置放置適當的標記。

am reciving the data fine but但是當我嘗試添加數據到一個新的谷歌地圖圖像構造它的錯誤,我檢查了一個警告,正確的信息在那裏,

// the following code will wor!!! 
        new google.maps.Size(32,37) // The Size works 
//The following line breaks it with dynamic value  
        new google.maps.Size(myIconArray.icon[myData.name_etp].size) 

繼承人的全碼: (在代碼的靜態線的測試值是存儲在所述對象的引用我想提出的相同值) http://www.focus-on-plants.com/locator_iconed.php

function addMarker(map, myData){ 
     console.log(myData) 
     // Create the marker 
     // create the marker info first 
     myLatLng = new google.maps.LatLng(myData.lat_mdt, myData.lng_mdt); 
     markersArray.push(myLatLng); 
     markersInfoArray.push(myData); 

     // ---------------------------- 
     // NOW CREATE THE ACTUAL ICON 
     //alert(myIconArray.icon[myData.name_etp].size) 

     /*var iconimage = new google.maps.MarkerImage(
     '/images/icons/markers/flower_lb/image_med.png', //myIconArray.icon[myData.name_etp].image, 
     new google.maps.Size(myIconArray.icon[myData.name_etp].size) // The Size 
     //new google.maps.Point(myIconArray.icon[myData.name_etp].origin), // The origin 
     //new google.maps.Point(myIconArray.icon[myData.name_etp].anchorpoint) // The anchor 
    );*/ 
     //console.log(iconimage) 
     var iconshape = { 
     type: 'poly', 
     coord: [0,2,1,2,1,1,18,0,18,1,19,2,20,19,19,19,18,21,14,21,10,26,5,21,1,21,1,20,0,20,0,2] 
     } 

     //alert(myIconArray.shape[myData.name_etp]) 
     mySize = 'new google.maps.Size('+myIconArray.icon[myData.name_etp].size+')' 
     var iconimage = new google.maps.MarkerImage(
     myIconArray.icon[myData.name_etp].image, 
     // the following code works!!! 
         new google.maps.Size(32,37) // The Size works 
         //The following line breaks iot with dynamic value  
         //new google.maps.Size(myIconArray.icon[myData.name_etp].size) 


     //new google.maps.Point(0, 0), // The origin 
     //new google.maps.Point(13,29) // The anchor 
    ); 
     var iconshadow = new google.maps.MarkerImage(
     '/images/icons/markers/flower_lb/shadow_med.png', 
     new google.maps.Size(42,18), // The Size 
     new google.maps.Point(0,0), // The origin 
     new google.maps.Point(13,18) // The anchor 
    ); 

     var marker = new google.maps.Marker({ 
     position: myLatLng, 
     map: map, 
     title: myData.name_mdt, 
     icon: iconimage, 
     shadow: iconshadow//, 
     //shape: iconshape 
     }); 

     // Wrapping the event listener inside an anonymous function 
     // that we immediately invoke and passes the variable i to. 
     (function(myData, marker) { 
     // Creating the event listener. It now has access to the values of 
     // myData and marker as they were during its creation 
     google.maps.event.addListener(marker, 'click', function() { 
     //create thecontent for the infowindow 
     var content = createContent(myData); 
     var infowindow = new google.maps.InfoWindow({ 
     content: content 
     }); 
     infowindow.open(map, marker); 
     }); 
     })(myData, marker); 

    }; 

回答

2

行,所以我發現這是爲什麼,

我經過new google.maps.Size(myIconArray.icon[myData.name_etp].size)

谷歌圖片maps.size取的兩個獨立的參數,new google.maps.Size(42,18)

我經過32, 37這是actualy一個字符串,

我需要使用到分割字符串下列內容:

tmp = myIconArray.icon[myData.name_etp].size.split(",")

然後加入x和y對於我使用的尺寸:new google.maps.Size(tmp[0], tmp[1])