Ec (2); based on some online materials, I have rewritten a Geo class that is convenient for obtaining Latitude and longitude information. Latitude and Longtitude are Latitude and longitude respectively. The most important constructor is to pass in the place name and obtain the latitude and longitude values from GoogleMap through Webrequest. GeognewGeo (& quot; beijing Normal University & quot;); then g. latitude and g. longt script ec (2); script
Based on some information on the Internet, I modified a Geo class that is convenient for obtaining Latitude and longitude information. Latitude and Longtitude are Latitude and longitude respectively. The most important constructor is to pass in the place name and obtain the latitude and longitude values from Google Map through Webrequest. It can be conveniently called in projects that contain geographical location information, that is, Geo g = new Geo ("Beijing Normal University"); then g. latitude and g. longtitude is the latitude and longitude of Beijing Normal University. They are 39.9614580 and 116.3692820 respectively. The implementation of Geo is as follows:
Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Net;
Using System. IO;
Namespace YourNameSpace
{
///
/// A class for latitude and longtitude
///
[Serializable]
Public class Geo
{
///
/// Latitude
///
Private string _ latitude = "";
///
/// Longtitude
///
Private string _ longtitude = "";
///
/// Default constructor
///
Public Geo ()
{
}
///
/// Construct geo given latitude and longtitude
///
///
///
Public Geo (string latitude, string longtitude)
{
_ Latitude = latitude;
_ Longtitude = longtitude;
}
///
/// Construct geo given name of a place
///
///
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];
}
}
///
/// Get latitude (latitude)
///
Public string Latitude
{
Get {return _ latitude ;}
Set {_ latitude = value ;}
}
///
/// Get longtitude (longitude)
///
Public string Longtitude
{
Get {return _ longtitude ;}
Set {_ longtitude = value ;}
}
}