google earth api中getGetChildren()方法出错,请大家帮忙
功能很简单,我想点一下button3就将Kml中place的子要素都显示到listBox1中;
可是老是在程序读到FeatureCollectionGE ft3ftlist = ft3.GetChildren()时出现错误
错误显示“值不在预期的范围内”。
代码如下:
首先是My town.xml文件:
<Folder>
<name>place</name>
<open>1</open>
<Placemark id="1">
<name>hospital</name>
<description>市立医院</description>
<LookAt>
<longitude>117.3554107588237</longitude>
<latitude>25.97005766898491</latitude>
<altitude>0</altitude>
<heading>2.256444518764292e-011</heading>
<tilt>0</tilt>
<range>812.0856138447672</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#m_ylw-pushpin</styleUrl>
<Point>
<coordinates>117.3586386280079,25.97048524562068,0</coordinates>
</Point>
</Placemark>
<Placemark id="2">
<name>sGate</name>
<description>南门头</description>
<LookAt>
<longitude>117.3616503117548</longitude>
<latitude>25.96799945520306</latitude>
<altitude>0</altitude>
<heading>0.002732212298384648</heading>
<tilt>0</tilt>
<range>1918.526536444458</range>
<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
</LookAt>
<styleUrl>#m_ylw-pushpin</styleUrl>
<Point>
<coordinates>117.3578946535116,25.97273565422709,0</coordinates>
</Point>
</Placemark>
</Folder>
然后是button3的事件:
private void button3_Click(object sender, EventArgs e)
{
GeTest.OpenKmlFile("D:/Kml/My town.kml", 1);
//将子元素加到列表框中
FeatureGE ft3 = GeTest.GetFeatureByName("place");
//ft3.GetChildren();
string[] ftNameList = null;
FeatureCollectionGE ft3ftlist = ft3.GetChildren();
ftNameList = new string[ft3ftlist.Count];
for (int i = 0; i < ft3ftlist.Count - 1; i++)
{
ftNameList[i] = ft3ftlist[i].Name;
}
listBox1.Items.Clear();
listBox1.Items.AddRange(ftNameList);
}
我在调试时加上断点显示我的ft3ftlist的数值为null,然道我没有在Kml文件中取到“place”的子元素么?
我Kml文件有问题吗?请各位高手教我