zoukankan      html  css  js  c++  java
  • google地图经纬度查询代码

    1:  // Taipei 101

       2:  string address = "台北市信義路五段七號101樓";
       3:   
       4:  // 查詢經緯度
       5:  string output = "csv";
       6:  string key = "ABQIAAAAXDq__hWKi9eMCwnn7LrMCxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSnSVp_Xlsd4Ph5iyMua7PE5E0x_A";
       7:  string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}&key={2}", address, output, key);
       8:   
       9:  WebClient wc = new WebClient();
      10:   
      11:  // 讀取結果
      12:  Stream s = wc.OpenRead(url);
      13:  StreamReader sr = new StreamReader(s, Encoding.UTF8);
      14:  string result = sr.ReadToEnd();
      15:   
      16:  // 解析 200,8,25.033408,121.564099  (HTTP status code, accuracy, latitude, longitude)
      17:  string[] tmpArray = result.Split(',');
      18:  string latitude = tmpArray[2];
      19:  string longitude = tmpArray[3];
      20:   
      21:  MessageBox.Show(string.Format("緯度: {0}, 經度: {1}", latitude, longitude), address, 
      22:  MessageBoxButtons.OK, MessageBoxIcon.Information);

    使用 HttpWebRequest、HttpWebResponse 類別:

       1:  // Taipei 101
       2:  string address = "台北市信義路五段七號101樓";
       3:   
       4:  // 查詢經緯度
       5:  string output = "csv";
       6:  string key = "ABQIAAAAXDq__hWKi9eMCwnn7LrMCxT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSnSVp_Xlsd4Ph5iyMua7PE5E0x_A";
       7:  string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}&key={2}", address, output, key);
       8:   
       9:  // 送出要求
      10:  HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
      11:   
      12:  // 取得回應
      13:  HttpWebResponse response = (HttpWebResponse) request.GetResponse();
      14:   
      15:  // 讀取結果
      16:  StreamReader sr = new StreamReader(response.GetResponseStream());
      17:   
      18:  // 解析 200,8,25.033408,121.564099  (HTTP status code, accuracy, latitude, longitude)
      19:  string[] tmpArray = sr.ReadToEnd().Split(',');
      20:  string latitude = tmpArray[2];
      21:  string longitude = tmpArray[3];
      22:   
      23:  MessageBox.Show(string.Format("緯度: {0}, 經度: {1}", latitude, longitude), address,
      24:      MessageBoxButtons.OK, MessageBoxIcon.Information);

    如果代码查询的蛮足不了你的要求,可以去这里看看

    http://www.playgoogle.com/googlemap/tool1.html


       本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢

  • 相关阅读:
    Datatable导出到Excel
    C# 连接EXCEL和ACCESS字符串2003及2007版字符串说明
    C#-读取写入Excel
    简易的命令行入门教程:
    日志记录
    python环境管理器的选择
    go语言的模块处理
    pip 使用国内源 安装类库
    go 实现单链表并使用一种常规实现翻转,一种使用递归实现翻转
    数据库产品选型
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1833864.html
Copyright © 2011-2022 走看看