Baidu map obtains the driving distance (non-linear distance) between two coordinates. c #,
Baidu interface:
Http://lbsyun.baidu.com/index.php? Title = webapi/route-matrix-api-v2
The start and end points are many-to-many relationships. If you only want to take two coordinates, take one coordinate for each.
The following method indicates that the obtained data is correct after testing. If the method is not completed, convert the json data by yourself.
/// <Summary> // get the driving distance based on the coordinate point. // </summary> // <param name = "origins"> Start coordinate </param>/ // <param name = "destinations"> end coordinate </param> // <returns> </returns> public static string GetDistance (string origins, string destinations) {try {// test data origins = "22.823331, 108.326998"; destinations = "22.832541, 108.321788 | 22.83841, 108.294974 | 22.817868, 108.425637 | 22.883959, 108.305368 | 22.83334, 108.32637 "; // distance to str Ing url = "http://api.map.baidu.com/routematrix/v2/driving"; string ak = "595eRciHjA0MG4TmhTm5ak58M00bQand"; string param = string. format ("origins = {0} & destinations = {1} & output = json & ak = {2}", origins, destinations, ak); string strURL = url + '? '+ Param; System. net. httpWebRequest request; request = (System. net. httpWebRequest) WebRequest. create (strURL); request. method = "GET"; System. net. httpWebResponse response; response = (System. net. httpWebResponse) request. getResponse (); System. IO. stream s; s = response. getResponseStream (); string StrDate = ""; string strValue = ""; StreamReader Reader = new StreamReader (s, Encoding. UTF8); while (StrDa Te = Reader. ReadLine ())! = Null) {strValue + = StrDate + "\ r \ n";} return strValue;} catch (Exception) {} return "";}