2
votes

Is there a way to use the response from the Google directions web service called, for example from C# code like this:

var url = System.String.Format(@"http://maps.googleapis.com/maps/api/directions/xml?origin={0}&destination={1}&sensor=false", 
  addressFrom, addressTo);
var result = XElement.Load(url);

And after that display the result on map; OR it must be done completely with JavaScript using the Google maps JavaScript API described here?

2

2 Answers

4
votes

Instead of writing all this xml code just use this open source project -code.google.com/p/google-maps/

0
votes

Try using System>Xml.Linq and create a method that return IEnumberable Elelment

See Details Below

using System.Xml.Linq

        string mapurl = "http://maps.google.com/?q= from " + sourceaddres + " to " + destaddr + "&output=kml&view=text";
        XDocument mapsdocument = XDocument.Load(mapurl);
        XNamespace myNameSpace = XNamespace.Get("http://earth.google.com/kml/2.0");
        IEnumerable<XElement> myRoute = mapsdocument.Element(myNameSpace + "kml").Element(myNameSpace + "Document").Elements(myNameSpace + "Placemark").Elements(myNameSpace + "name");
        IEnumerable<XElement> myDescp = mapsdocument.Element(myNameSpace + "kml").Element(myNameSpace + "Document").Elements(myNameSpace + "Placemark").Elements(myNameSpace + "description");

   you can wrap this in a method and set return to IEnumerable<XElement>