百度接口了解:
http://lbsyun.baidu.com/index.php?title=webapi/route-matrix-api-v2
起點與終點為多對多關系,如果你只想取兩個坐標,那就各取一個坐標即可。
如下方法,經過測試,獲取的數據是正確的。方法沒寫完,自己轉json數據
/// <summary> /// 根據坐標點獲取駕車距離 /// </summary> /// <param name="origins">起點坐標</param> /// <param name="destinations">終點坐標</param> /// <returns></returns> public static string GetDistance(string origins, string destinations) { try { //測試數據 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"; //行車距離 string 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 ((StrDate = Reader.ReadLine()) != null) { strValue += StrDate + "\r\n"; } return strValue; } catch (Exception) { } return ""; }