google earth api中getGetChildren()方法出错,请大家帮忙

firedrose 2013-03-07 03:50:15

功能很简单,我想点一下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文件有问题吗?请各位高手教我
...全文
113 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
我是小李 2013-03-07
  • 打赏
  • 举报
回复
FeatureGE ft3 = GeTest.GetFeatureByName("place"); 这句是什么意思,假如想读取XML的话可以使用xPath或者linq to xml
firedrose 2013-03-07
  • 打赏
  • 举报
回复
啊自己解决了,时ft3ftlist[0].Name没有数值
firedrose 2013-03-07
  • 打赏
  • 举报
回复
GeTest 是一个ApplicationGEClass的类,我在程序初始化的时候加载过了,ApplicationGEClass GeTest = new ApplicationGEClass(); 我现在发现时在ftNameList[i] = ft3ftlist[i].Name;时出错的,断点在这时,调试到就报值不在预期的范围内。不是我刚刚说的“FeatureCollectionGE ft3ftlist = ft3.GetChildren()时出现错误”

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧