truedeity Posted January 10, 2010 Posted January 10, 2010 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Linq; namespace LiquidFrameworks.GoogleMaps { public class Route { public string To { get; set; } public string From { get; set; } } public class GoogleMaps : IEnumerable<string> { Route Agenda = new Route(); public GoogleMaps(string to, string from) { Agenda.To = to; Agenda.From = from; } public List<string> GetDirections(Route Agenda) { string mapsURL = @"http://maps.google.com/?q=From " + Agenda.To + " To " + Agenda.From + "&output=kml"; XDocument mapsDocument = XDocument.Load(mapsURL); XNamespace myNS = XNamespace.Get(@"http://earth.google.com/kml/2.0"); var result = from e in mapsDocument.Element(myNS + "kml").Element(myNS + "Document").Elements(myNS + "Placemark").Elements(myNS + "name") select (string)e; return result.ToList(); } #region IEnumerable<string> Members public IEnumerator<string> GetEnumerator() { foreach (string i in GetDirections(Agenda)) { yield return i; } } #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } #endregion } } Merged post follows: Consecutive posts mergedI created this object so that other people can reuse google maps without calling special API.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now