码迷,mamicode.com
首页 > Windows程序 > 详细

百度地图 获取两点坐标之间的驾车距离(非直线距离) c#

时间:2016-09-26 17:48:28      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:

百度接口了解:

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

  

百度地图 获取两点坐标之间的驾车距离(非直线距离) c#

标签:

原文地址:http://www.cnblogs.com/welia110/p/5909699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!