2011-02-07 18 views

回答

3

UK Government list of schools and colleges直接从英国政府网站,包括位置......你可能需要采取它的位置和距离邮政编码数据转换为纬度/长自己(可能)。

,链接到的其他数据集,包括学生成就和缺勤(由户籍所在地)

1

谷歌有它,如果你知道地址,你可以使用地理编码服务见this link。这段代码将查询谷歌某个地址的经纬度,一旦你的经度和纬度,你就可以画出你的谷歌地图上的学校的地位:

public string GeocodeAddress(string address) 
{ 
    DateTime startTime = DateTime.Now; 

    address = address.Replace(' ', '+'); 

    string url = string.Format(_GEOCODE_API_TEMPLATE, address, "csv", _GOOGLE_API_KEY); 

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); 

    IWebProxy proxy = WebRequest.DefaultWebProxy; 
    proxy.Credentials = CredentialCache.DefaultNetworkCredentials; 
    request.Proxy = proxy; 

    StringBuilder location = new StringBuilder(); 
    HttpWebResponse response = null; 
    try 
    { 
     response = (HttpWebResponse)request.GetResponse(); 

     if (response.StatusCode != HttpStatusCode.OK) 
      throw new System.Net.WebException(string.Format("Bad response code: {0}", response.StatusCode)); 

     StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8")); 
     char[] chars = new char[256]; 
     int pos = 0; 
     int numCharsRead = 0; 
     while ((numCharsRead = sr.Read(chars, 0, chars.Length)) > 0) 
     { 
      pos += numCharsRead; 
      location.Append(chars, 0, numCharsRead); 
     } 
    } 
    finally 
    { 
     if (response != null) 
      response.Close(); 
    } 

    return location.ToString(); 
} 

返回的位置,然后需要被解析:

float latitude, longitude; 
float.TryParse(ar.RawGeocode.Split(',')[2], out latitude); 
float.TryParse(ar.RawGeocode.Split(',')[3], out longitude); 

用于查询谷歌API的URL是:

private const string _GEOCODE_API_TEMPLATE = "http://maps.google.com/maps/geo?q={0}&output={1}&key={2}"; 

key的被应用于与由谷歌产生,并且是PA与您的请求域相关。你可以免费获得这个密钥(并因此使用服务),但它是速率有限的 - 我上次检查他们限制你每天5万个请求。我忘记了你去申请钥匙的网址,但是如果你是谷歌的话,你应该不会有太大的问题....哼:)

相关问题