public Address GetAddressFromLatLong(double latitude, double longitude) { if (!CoordinateValidator.Validate(latitude, longitude)) { throw new ArgumentException("Invalid coordinate supplied."); } XDocument doc = XDocument.Load(String.Format(ApiReverseGeoCode, latitude, longitude)); var result = doc.Descendants("result").First(); return(result != null ? new Address { FormattedAddress = result.Descendants("formatted_address").First().Value, StreetNumber = result.Descendants("address_component").First(x => x.Descendants("type").Any(y => y.Value == "street_number")).Descendants("short_name").First().Value, StreetName = result.Descendants("address_component").First(x => x.Descendants("type").Any(y => y.Value == "route")).Descendants("short_name").First().Value, City = result.Descendants("address_component").First(x => x.Descendants("type").Any(y => y.Value == "locality")).Descendants("short_name").First().Value, State = result.Descendants("address_component").First(x => x.Descendants("type").Any(y => y.Value == "administrative_area_level_1")).Descendants("short_name").First().Value, ZipCode = result.Descendants("address_component").First(x => x.Descendants("type").Any(y => y.Value == "postal_code")).Descendants("short_name").First().Value, Country = result.Descendants("address_component").First(x => x.Descendants("type").Any(y => y.Value == "country")).Descendants("long_name").First().Value, County = result.Descendants("address_component").First(x => x.Descendants("type").Any(y => y.Value == "administrative_area_level_2")).Descendants("short_name").First().Value } : null); }
public Directions GetDirections(Coordinate origin, Coordinate destination, TravelMode travelMode = TravelMode.Driving) { if (!CoordinateValidator.Validate(origin.Latitude, origin.Longitude)) { throw new ArgumentException("Invalid origin coordinate supplied."); } if (!CoordinateValidator.Validate(destination.Latitude, destination.Longitude)) { throw new ArgumentException("Invalid destination coordinate supplied."); } return(GetDirections(XDocument.Load(String.Format(ApiDirections, String.Format("{0},{1}", origin.Latitude, origin.Longitude), String.Format("{0},{1}", destination.Latitude, destination.Longitude), travelMode.ToString().ToLower())))); }