通过Google Maps API v3访问ExtendedData信息 [英] Accessing ExtendedData information via Google Maps API v3

查看:156
本文介绍了通过Google Maps API v3访问ExtendedData信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在每个< Placemark> 节点和< ExtendedData> 节点中都有一个KML文件,然后使用键/值对的多个< Data> 节点。我遵循以下示例: http://code.google.com/apis/kml/documentation/extendeddata.html code.google.com/apis/kml/documentation/ kmlelementsinmaps.html建议地图支持KML ExtendedData节点(尽管部分),但是我找不到通过javascript访问ExtendedData对象的方法。我使用的是:

  google.maps.event.addListener(agency_layer,'click',function(kmlEvent){
console.debug(kmlEvent);
}

(其中agency_layer是KML对象)。
kmlEvent包含所有的KML特性数据,但不包含extendedData,而我正在摸索我的头。我想让我的KML在语义上合理,而不是将更多数据加载到描述中并稍后解析它javascript。



有没有人有过类似的经历,或者知道如何通过Google Maps API v3访问ExtendedData节点?

解决方案

我在寻找完全相同的东西,我从我找到的信息构建了一个jQuery解决方案 。这是我写的功能。

  function extendedDataToArray(feature)
{
var returnArray = new Array();
$(feature.getKml())。find(Data)。each(function()
{
returnArray [$(this).attr(name)] = $ (this).find(value).text();
}
);
return returnArray;





$ p

该函数返回一个关联数组,其中的键等于数据元素的名称,并将值作为值标签的内容。希望这有助于!


I have a KML file which contains within each <Placemark> node an <ExtendedData> node, and then a number of <Data> nodes with key/value pairs. I've followed the examples at: http://code.google.com/apis/kml/documentation/extendeddata.html and code.google.com/apis/kml/documentation/kmlelementsinmaps.html suggests maps do support KML ExtendedData nodes (albeit partially), but I cannot find a way of accessing the ExtendedData object via javascript. I'm using:

google.maps.event.addListener(agency_layer, 'click', function(kmlEvent) {
  console.debug( kmlEvent );
}

(where agency_layer is the KML object). kmlEvent contains all of the KML feature data, but not the extendedData, and i'm scratching my head. I want to make my KML semantically sensible, rather than loading more data into the description and parsing it later with javascript.

has anyone had a similar experience, or knows how to access ExtendedData nodes via Google Maps API v3?

解决方案

I was looking for the exact same thing. I constructed a jQuery solution from the information I found here.

Since jQuery can parse xml easily, and kml is xml, it works out pretty well. Here's the function I wrote.

function extendedDataToArray(feature)
{
    var returnArray = new Array();
    $(feature.getKml()).find("Data").each(function()
    {
        returnArray[$(this).attr("name")] = $(this).find("value").text();
    }
    );
    return returnArray;
}

The function returns an associative array with keys equal to the names of your data elements, and values as the content of your value tags. Hope this helps!

这篇关于通过Google Maps API v3访问ExtendedData信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆