-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGeocodeService.cs
35 lines (28 loc) · 1.03 KB
/
GeocodeService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Globalization;
namespace Geocoder {
public class GeocodeService {
private WebClient _client;
public GeocodeService() {
_client = new WebClient();
}
public Location GeocodeLocation(string address) {
var url = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=" + System.Web.HttpUtility.UrlEncode(address);
var xmlString = _client.DownloadString(url);
var xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml(xmlString);
var loc = new Location();
loc.Latitude = Double.Parse(xmlDoc.SelectSingleNode("//geometry/location/lat").InnerText, NumberFormatInfo.InvariantInfo);
loc.Longitude = double.Parse(xmlDoc.SelectSingleNode("//geometry/location/lng").InnerText, NumberFormatInfo.InvariantInfo);
return loc;
}
//public Task GeocodeLocationAsync(string address) {
// return null;
//}
}
}