zoukankan      html  css  js  c++  java
  • C#获取Google Map对应地名的经纬度值

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.IO;

    namespace YourNameSpace
    {
        
    /// <summary>
        
    /// a class for latitude and longtitude
        
    /// </summary>
        [Serializable]
        
    public class Geo
        {
            
    /// <summary>
            
    /// latitude
            
    /// </summary>
            private string _latitude = "";

            
    /// <summary>
            
    /// longtitude
            
    /// </summary>
            private string _longtitude = "";

            
    /// <summary>
            
    /// default constructor
            
    /// </summary>
            public Geo()
            {

            }

            
    /// <summary>
            
    /// construct geo given latitude and longtitude
            
    /// </summary>
            
    /// <param name="latitude"></param>
            
    /// <param name="longtitude"></param>
            public Geo(string latitude, string longtitude)
            {
                _latitude 
    = latitude;
                _longtitude 
    = longtitude;
            }
            
            
    /// <summary>
            
    /// construct geo given name of a place
            
    /// </summary>
            
    /// <param name="location"></param>
            public Geo(string location)
            {
                
    string output = "csv";
                
    string url = string.Format("http://maps.google.com/maps/geo?q={0}&output={1}", location, output);
                HttpWebRequest request 
    = (HttpWebRequest)WebRequest.Create(url);
                HttpWebResponse response 
    = (HttpWebResponse)request.GetResponse();
                
    using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    
    string[] tmpArray = sr.ReadToEnd().Split(',');
                    _latitude 
    = tmpArray[2];
                    _longtitude 
    = tmpArray[3];
                }
            }

            
    /// <summary>
            
    /// get latitude(纬度)
            
    /// </summary>
            public string Latitude
            {
                
    get { return _latitude; }
                
    set { _latitude = value; }
            }

            
    /// <summary>
            
    /// get longtitude(经度)
            
    /// </summary>
            public string Longtitude
            {
                
    get { return _longtitude; }
                
    set { _longtitude = value; }
            }
        }
    }

    转自:http://www.cnblogs.com/yazdao/archive/2010/01/22/1654179.html
    谢谢分享

  • 相关阅读:
    wince嵌入式应用程序开发环境搭建
    用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败
    git# 建立个人级服务器仓库 git init bare
    Bind和Eval的区别详解
    控件包含代码块(即 <% ... %>),因此无法修改控件集合 (转自http://blog.csdn.net/wangchao1982/archive/2007/11/19/1892472.aspx)
    Sys.ArgumentOutOfRangeException: Value must be an integer 错误的原因
    判断Cookies是否处于开启状态
    多个解决方案引用同一工程文件时冲突的解决方法
    javascript无提示的关闭页面
    Server.MapPath()
  • 原文地址:https://www.cnblogs.com/activities/p/2112438.html
Copyright © 2011-2022 走看看