Baidu map obtains the driving distance (non-linear distance) between two coordinates. c #,

Source: Internet
Author: User

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 "";}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.