Where can i get the lat long for uk schools?
I would like to include school locations on my google maps and iff possible some data about the schoo开发者_开发技巧l, any help would be greatly received.
Regards
Robbie
UK Government list of schools and colleges straight from the uk government web, including location... you'll probably need to take the location and convert it to a lat/long yourself (probably from postcode data).
See this link for links to additional datasets, including pupil attainment and absences (by location of residence)
Google has a geocoding service which you can use if you know the address. This piece of code will query Google for the latitude and longitude of an address, once you have the latitude and longitude you can then plot the school's position on your Google map:
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();
}
The location that is returned then needs to be parsed:
float latitude, longitude;
float.TryParse(ar.RawGeocode.Split(',')[2], out latitude);
float.TryParse(ar.RawGeocode.Split(',')[3], out longitude);
The URL used to query the Google API is:
private const string _GEOCODE_API_TEMPLATE = "http://maps.google.com/maps/geo?q={0}&output={1}&key={2}";
The key
is applied for and generated by Google, and is particular to your requesting domain. You can get this key (and therefore use the service) for free, but it is rate limited - last time i checked they limited you to 50K requests per day. I forget the URL where you go to apply for a key, but you shouldn't have much problem if you Google it.... heh :)
精彩评论