0

我正在使用javascript和v3的地圖API從融合表中提取一些數據。我已經成功地爲某些點添加了一些自定義標記,但現在正嘗試將我創建的標記「默認」添加到名爲「圖標」的我的表中的列中指定的圖標。我不使用融合表層,而是在數據的for循環中創建標記。在我的表中的圖標列有條目,如:'poi','星'等...Google Maps API - 從融合表中的字符串列中獲取圖標標記

有沒有任何方式使用名稱字符串以某種方式得到那些'默認'圖標像融合表層會呢?或者,有沒有人知道我可以在哪裏找到默認融合表圖標(例如POI和Star)的絕對位置,以便我可以在腳本中定義它們的路徑?

以下是一些示例代碼。如果有人知道Google上圖標的絕對URL,我可以編寫一個函數,根據'Icon'列中的字符串輸入。

 //if there's an image, use it as marker, else use default  
    if(row[3] != ''){ 
     // Create the marker 
     var marker = new google.maps.Marker({ 
     map: map, 
     position: coordinate, 
     icon: new google.maps.MarkerImage(row[3]) 
     });  
    } else { 
     // Create the marker 
     var marker = new google.maps.Marker({ 
     map: map, 
     position: coordinate 

     //icon: row[2] (row[2] is the Icon column. 
     // I'm assuming I'll just need a conditional to check 
     // for the name (such as 'poi') and then to put in the absolute URL for each respectively 
     // the problem is I don't know the absolute URL's for these icons. Thanks. 
     }); 
     } 

回答

1

我正在尋找幾乎完全相同的過程。雖然,我所做的只是在Fusion Table中的列中描述了標記,因此,就您而言,這將是「Poi」,「Star」等。我的作品是「照片」,「視頻」,「歌曲」。 「然後,代碼如下:

var image = new google.maps.MarkerImage('img/CF_Orange.png', 
    new google.maps.Size(25, 25), 
    new google.maps.Point(0,0), 
    new google.maps.Point(12.5,12.5)); 

    var image2 = new google.maps.MarkerImage('img/CF_Purple.png', 
    new google.maps.Size(25, 25), 
    new google.maps.Point(0,0), 
    new google.maps.Point(12.5,12.5)); 

    var image3 = new google.maps.MarkerImage('img/CF_Green.png', 
    new google.maps.Size(25, 25), 
    new google.maps.Point(0,0), 
    new google.maps.Point(12.5,12.5)); 

if(row[5] == 'photo'){ 
    var marker = new google.maps.Marker({ 
    map: map, 
    position: coordinate, 
    icon: image 
    });  
} else if(row[5] == 'video'){ 
    var marker = new google.maps.Marker({ 
    map: map, 
    position: coordinate, 
    icon: image2 
    }); 
} else { 
    var marker = new google.maps.Marker({ 
    map: map, 
    position: coordinate, 
    icon: image3 
    }); 
    }