【问题标题】:Google Maps API - Get icon marker from string column in fusion tableGoogle Maps API - 从融合表中的字符串列获取图标标记
【发布时间】:2011-09-14 23:05:59
【问题描述】:

我正在使用 javascript 和 v3 的地图 API 从 Fusion Table 中提取一些数据。我已经成功地向某些点添加了一些自定义标记,但现在我正在尝试将我创建的标记“默认”设置为从我的表格中名为“图标”的列中指定的图标。我没有使用融合表层,而是在数据的 for 循环中创建标记。我表中的 Icon 列包含以下条目:“poi”、“star”等...

有什么方法可以使用名称字符串以某种方式获取那些“默认”图标,就像融合表层一样?或者,有谁知道我在哪里可以找到默认融合表图标(例如 POI 和 Star)的绝对位置,以便我可以在脚本中定义它们的路径?

这是一些示例代码。如果有人知道谷歌上图标的绝对 URL,我可以编写一个函数来根据“图标”列中的字符串输入它。

      //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.
      });
        }

【问题讨论】:

    标签: javascript google-maps google-maps-api-3 google-maps-markers google-fusion-tables


    【解决方案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
      });
        }
    

    【讨论】:

      猜你喜欢
      • 2014-07-25
      • 2022-01-07
      • 1970-01-01
      • 2011-10-13
      • 1970-01-01
      • 2013-04-28
      • 2013-05-06
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多