国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

c# 通過經(jīng)緯度查詢 具體的地址和區(qū)域名稱

2020-01-24 03:39:02
字體:
來源:轉載
供稿:網(wǎng)友
最近項目需要通過經(jīng)緯度查詢 具體的地址和區(qū)域名稱,通過查詢網(wǎng)絡資源,發(fā)現(xiàn)提供的大多是得到具體的地址而對區(qū)域或城市名稱的獲取就不是很好把握;在這里自己搞了個:
復制代碼 代碼如下:

//webclient客戶端對象
WebClient client = new WebClient();
string url = "http://maps.google.com/maps/api/geocode/xml?latlng=" + latitude + "," + longitude + "&language=zh-CN&sensor=false";//請求地址
client.Encoding = Encoding.UTF8;//編碼格式
string responseTest = client.DownloadString(url);
//下載xml響應數(shù)據(jù)
string address = "";//返回的地址
XmlDocument doc = new XmlDocument();
//創(chuàng)建XML文檔對象
if (!string.IsNullOrEmpty(responseTest))
{
doc.LoadXml(responseTest);//加載xml字符串
//查詢狀態(tài)信息
string xpath = @"GeocodeResponse/status";
XmlNode node = doc.SelectSingleNode(xpath);
string status = node.InnerText.ToString();
if (status == "OK") {
//查詢詳細地址信息
xpath = @"GeocodeResponse/result/formatted_address";
node = doc.SelectSingleNode(xpath);
address = node.InnerText.ToString();
//查詢地區(qū)信息
XmlNodeList nodeListAll = doc.SelectNodes("GeocodeResponse/result");

XmlNode idt = nodeListAll[0];
XmlNodeList idts = idt.SelectNodes("address_component[type='sublocality']");
//address_component[type='sublocality']表示篩選type='sublocality'的所有相關子節(jié)點;
XmlNode idtst = idts[0];

string area = idtst.SelectSingleNode("short_name").InnerText;
address = address + "," + area;
}
}

address就是獲取到的具體地址信息和區(qū)域信息;
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阆中市| 韶关市| 闽清县| 竹北市| 宜州市| 吉木乃县| 广河县| 鹤山市| 靖江市| 东乌珠穆沁旗| 康平县| 瓮安县| 丹寨县| 呼图壁县| 平乡县| 新龙县| 民丰县| 调兵山市| 沐川县| 澎湖县| 临西县| 嘉黎县| 噶尔县| 汶上县| 浦城县| 平乡县| 汝城县| 邓州市| 隆化县| 洞头县| 都昌县| 盱眙县| 屏南县| 琼海市| 汾西县| 汽车| 安溪县| 柳州市| 凌海市| 韶山市| 孟村|