Referring to the online part of the data, they rewrote a convenient access to latitude and longitude information of the class Geo, where latitude and longtitude respectively are latitude and longitude. One of the most important constructors is the incoming place name, which is obtained by WebRequest from the Google Map, and can be easily invoked in a project that contains geographic information, GEO g = new Geo ("Beijing Normal University"), and then G. Latitude and G.longtitude are the latitude and longitude of Beijing Normal University, which are 39.9614580, 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
{
<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 (PS tutorial. Google.com/maps/geo?q={0}&output={1 ">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 (latitude)
</summary>
public string Latitude
{
get {return _latitude;}
set {_latitude = value;}
}
///<summary>
/ Get Longtitude (longitude)
///</summary>
public string Longtitude
{
get {return _longtitude;}
set {_longtitude = value;}
}
}