用C#从百度地图API中获得城市编码
这是用百度地图的api获得的XML数据,怎么单独得到城市代码?<?xmlversion="1.0"encoding="utf-8"?><GeocoderSearchRes...
这是用百度地图的api获得的XML数据,怎么单独得到城市代码?
<?xml version="1.0" encoding="utf-8" ?>
<GeocoderSearchResponse>
<status>0</status>
<result>
<location>
<lat>36.92280591755</lat>
<lng>117.01815000544</lng>
</location>
<formatted_address>山东省济南市济阳县</formatted_address>
<business></business>
<addressComponent>
<streetNumber></streetNumber>
<street></street>
<district>济阳县</district>
<city>济南市</city>
<province>山东省</province>
<country>中国</country>
<countryCode></countryCode>
<direction></direction>
<distance></distance>
</addressComponent>
<cityCode>288</cityCode>
<pois>
</pois>
<poiRegions>
</poiRegions>
<sematic_description></sematic_description>
</result>
</GeocoderSearchResponse> 展开
<?xml version="1.0" encoding="utf-8" ?>
<GeocoderSearchResponse>
<status>0</status>
<result>
<location>
<lat>36.92280591755</lat>
<lng>117.01815000544</lng>
</location>
<formatted_address>山东省济南市济阳县</formatted_address>
<business></business>
<addressComponent>
<streetNumber></streetNumber>
<street></street>
<district>济阳县</district>
<city>济南市</city>
<province>山东省</province>
<country>中国</country>
<countryCode></countryCode>
<direction></direction>
<distance></distance>
</addressComponent>
<cityCode>288</cityCode>
<pois>
</pois>
<poiRegions>
</poiRegions>
<sematic_description></sematic_description>
</result>
</GeocoderSearchResponse> 展开
1个回答
展开全部
//从百度获取到的地图相关的XML内容
string xmlData = string.Empty;
XmlDocument doc = new XmlDocument();
//doc.Load(@"D:\csharp\output\output\loc.xml");
doc.LoadXml(xmlData);
XmlNode node = doc.SelectSingleNode("GeocoderSearchResponse/result/cityCode");
if (node != null)
{
Console.WriteLine(node.InnerText);
}
Console.ReadLine(); Console.ReadLine();
string xmlData = string.Empty;
XmlDocument doc = new XmlDocument();
//doc.Load(@"D:\csharp\output\output\loc.xml");
doc.LoadXml(xmlData);
XmlNode node = doc.SelectSingleNode("GeocoderSearchResponse/result/cityCode");
if (node != null)
{
Console.WriteLine(node.InnerText);
}
Console.ReadLine(); Console.ReadLine();
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询