Jump to content

How To Create A Google Maps IEnumerable Object In C#.NET With Linq To XML

Featured Replies

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 merged

I created this object so that other people can reuse google maps without calling special API.

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.