实名认证用户熊川湘 身份证号码430811198506290914

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

posted @ 2010-09-24 14:11  浪达短信群发  阅读(1110)  评论(0编辑  收藏  举报