zoukankan      html  css  js  c++  java
  • Google Map 根据坐标 获取地址信息

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Xml;
     6 using System.Net;
     7 
     8 namespace Utility
     9 {
    10     public class GoogleMapHelper
    11     {
    12         public string GetAddress(string lat, string lng)
    13         {
    14             WebClient client = new WebClient();
    15             string url = string.Format("http://maps.google.com/maps/api/geocode/xml?latlng={0},{1}&language=zh-CN&sensor=false", lat, lng);
    16             client.Encoding = Encoding.UTF8;
    17             try
    18             {
    19                 string responseTest = client.DownloadString(url);
    20                 XmlDocument doc = new XmlDocument();
    21 
    22                 if (!string.IsNullOrEmpty(responseTest))
    23                 {
    24                     doc.LoadXml(responseTest);
    25 
    26                     string xpath = @"GeocodeResponse/status";
    27                     XmlNode node = doc.SelectSingleNode(xpath);
    28                     string status = node.InnerText.ToString();
    29 
    30                     if (status == "OK")
    31                     {
    32                         xpath = @"GeocodeResponse/result/formatted_address";
    33                         node = doc.SelectSingleNode(xpath);
    34                         string address = node.InnerText.ToString();
    35                         return address;
    36                     }
    37                 }
    38             }
    39             catch
    40             {
    41             }
    42             return "";
    43         }
    44     }
    45 }
  • 相关阅读:
    Nginx调试入门
    Nginx自动安装脚本
    Centos7.3自动化脚本安装MySQL5.7
    复制多行内容到文本
    Windows常用命令
    C++笔试题
    loadrunner和QTP视频教程汇总
    mysql-connector-java-5.1.22下载
    struts学习笔记
    Hibernate原理
  • 原文地址:https://www.cnblogs.com/erictanghu/p/3595747.html
Copyright © 2011-2022 走看看