Translate Driving directions from Google Maps in XML format


In this example, It has been demonstrated on how you can integrate the Keyhole Markup Language  KML  document in using C Sharp. The Google maps return this document in result of Http request sent by the user which contains the data for direction and distance. You will see the implementation and translation when you walk in to the code. Use Linq allows XML data to be queried by using the standard query operators as well as tree-specific operators that provide XPath-like navigation through descendants, ancestors, and siblings. It simplifies working with XML data without having to resort to using additional language syntax like XPath or XQuery. You can use LINQ to XML to perform LINQ queries over XML that you retrieve from the file system, from a remote web service, or from in-memory XML content. 

Figure 1

Using the code

The first thing we will do is add the namespaces we will be using. Our code-behind will look something like this:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Xml;

Figure 2

Line 1:   XNamespace obj_XNameSpace = XNamespace.Get("");
Line 2:   string Des_Source_URL = " " + txtDestination.Text + " to " + txtSource.Text + "&output=kml&view=text";

Before going into detail there are some points to keep in mind.

1: XNamespace ("") this will works as a namespace for which we will use to parse the KML for the specified Uniform Resource Identifier 
2: Browser Qurey "from_address" to "to_address" "&output=kml&view=text"; (where "from" and "to" are the keywords).
3: The "output" parameter retrieves the result in the given format which will be KML in this case.