1 /// <summary>2 ///returns driving distance in kilometers3 /// </summary>4 /// <param Name= "origin" ></param>5 /// <param name= "Destination" ></param>6 /// <returns></returns>7 Public Static DoubleGetdrivingdistanceinkilometers (stringOriginstringdestination)8 { 9 stringURL =@"http://maps.googleapis.com/maps/api/distancematrix/xml?origins="+TenOrigin +"&destinations="+ Destination + One "&mode=driving&sensor=false&language=en-en&units=imperial"; A -HttpWebRequest request =(HttpWebRequest) webrequest.create (URL); -WebResponse response =request. GetResponse (); theStream DataStream =Response. GetResponseStream (); -StreamReader Sreader =NewStreamReader (dataStream); - stringResponsereader =Sreader. ReadToEnd (); - Response. Close (); + -XmlDocument xmldoc =NewXmlDocument (); + xmldoc. LOADXML (Responsereader); A at - if(xmldoc. getElementsByTagName ("Status")[0]. childnodes[0]. InnerText = ="OK") - { -XmlNodeList distance = xmldoc. getElementsByTagName ("Distance"); - varMiledistance = convert.todouble (distance[0]. childnodes[1]. Innertext.replace ("mi","")); - varKmdistance = (Miledistance *1.609344). ToFixed (1); in returnkmdistance; - } to + return 0; -}
Code Snippets-C # calculates distances based on Google API