Вот функция, которая будет возвращать координаты в словаре. Примечание: это с новым API V3. Ключ API не требуется. датчик есть.
// Figure out the geocoordinates for the location
private Dictionary<string, string> GeoCode(string location)
{
// Initialize the dictionary with empty values.
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("latitude", "");
dic.Add("longitude", "");
try
{
string url = "http://maps.google.com/maps/api/geocode/xml?address=" + System.Web.HttpUtility.UrlEncode(location) + "&sensor=false";
XmlDocument doc = new XmlDocument();
doc.Load(url);
XmlNodeList nodes = doc.SelectNodes("//location");
// We're assuming there's only one location node in the xml.
foreach (XmlNode node in nodes)
{
dic["latitude"] = node.SelectSingleNode("lat").InnerText;
dic["longitude"] = node.SelectSingleNode("lng").InnerText;
}
}
catch (Exception)
{
// If anything goes wrong, we want to get empty values back.
dic["latitude"] = "";
dic["longitude"] = "";
}
return dic;
}