百度地图如何计算两点之间距离

Python调用百度地图API实现路径规划提取真实距离、时间 阅读详情


百度地图如何计算两点之间距离

分类: 算法 15819人阅读 评论(4) 收藏 举报

路线规划提供了获取路线距离的方法,见MKRoutePlan 类的 getDistance 方法。

如果是计算任意两点的距离,自2.0.0版本开始,Android SDK为开发者提供了计算距离的接口(DistanceUtil),具体使用方法如下:

1.GeoPoint p1LL = new GeoPoint(39971802, 116347927);

2.GeoPoint p2LL = new GeoPoint(39892131, 116498555);

3.double distance = DistanceUtil.getDistance(p1LL, p2LL);

如果开发者使用的是1.3.5及以前的版本,在计算任意两点之前的距离时,有如下两种方法:一种利用勾股定理计算,适用于两点距离很近的情况;一种按标准的球面大圆劣弧长度计算,适用于距离较远的情况。

<ol style="margin: 0px; padding: 0px;"><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">1</span>.	<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">static</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> DEF_PI <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="nu0" style="color: rgb(204, 102, 204);">3.14159265359</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span> <span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// PI</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">2</span>.	<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">static</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> DEF_2PI<span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="nu0" style="color: rgb(204, 102, 204);">6.28318530712</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span> <span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 2*PI</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">3</span>.	<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">static</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="nu0" style="color: rgb(204, 102, 204);">0.01745329252</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span> <span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// PI/180.0</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">4</span>.	<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">static</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> DEF_R <span class="sy0" style="color: rgb(51, 153, 51);">=</span><span class="nu0" style="color: rgb(204, 102, 204);">6370693.5</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span> <span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// radius of earth</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">5</span>.	<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">public</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> GetShortDistance<span class="br0" style="color: rgb(0, 153, 0);">(</span><span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> lon1, <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> lat1, <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> lon2, <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> lat2<span class="br0" style="color: rgb(0, 153, 0);">)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">6</span>.	<span class="br0" style="color: rgb(0, 153, 0);">{</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">7</span>.		<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> ew1, ns1, ew2, ns2<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">8</span>.		<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> dx, dy, dew<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">9</span>.		<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> distance<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">10</span>.		<span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 角度转换为弧度</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">11</span>.		<span class="me1" style="color: rgb(0, 102, 51);">ew1</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> lon1 <span class="sy0" style="color: rgb(51, 153, 51);">*</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">12</span>.		<span class="me1" style="color: rgb(0, 102, 51);">ns1</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> lat1 <span class="sy0" style="color: rgb(51, 153, 51);">*</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">13</span>.		<span class="me1" style="color: rgb(0, 102, 51);">ew2</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> lon2 <span class="sy0" style="color: rgb(51, 153, 51);">*</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">14</span>.		<span class="me1" style="color: rgb(0, 102, 51);">ns2</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> lat2 <span class="sy0" style="color: rgb(51, 153, 51);">*</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">15</span>.		<span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 经度差</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">16</span>.		<span class="me1" style="color: rgb(0, 102, 51);">dew</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> ew1 <span class="sy0" style="color: rgb(51, 153, 51);">-</span> ew2<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">17</span>.		<span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 若跨东经和西经180 度,进行调整</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">18</span>.		<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">if</span> <span class="br0" style="color: rgb(0, 153, 0);">(</span>dew <span class="sy0" style="color: rgb(51, 153, 51);">></span> DEF_PI<span class="br0" style="color: rgb(0, 153, 0);">)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">19</span>.		<span class="me1" style="color: rgb(0, 102, 51);">dew</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> DEF_2PI <span class="sy0" style="color: rgb(51, 153, 51);">-</span> dew<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">20</span>.		<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">else</span> <span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">if</span> <span class="br0" style="color: rgb(0, 153, 0);">(</span>dew <span class="sy0" style="color: rgb(51, 153, 51);"><</span> <span class="sy0" style="color: rgb(51, 153, 51);">-</span>DEF_PI<span class="br0" style="color: rgb(0, 153, 0);">)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">21</span>.		<span class="me1" style="color: rgb(0, 102, 51);">dew</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> DEF_2PI <span class="sy0" style="color: rgb(51, 153, 51);">+</span> dew<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">22</span>.		<span class="me1" style="color: rgb(0, 102, 51);">dx</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> DEF_R <span class="sy0" style="color: rgb(51, 153, 51);">*</span> <a target=_blank style="color: rgb(0, 136, 204); text-decoration: none;" href="http://www.google.com/search?hl=en&q=allinurl%3Amath+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3" style="color: rgb(0, 51, 153);">Math</span></a>.<span class="me1" style="color: rgb(0, 102, 51);">cos</span><span class="br0" style="color: rgb(0, 153, 0);">(</span>ns1<span class="br0" style="color: rgb(0, 153, 0);">)</span> <span class="sy0" style="color: rgb(51, 153, 51);">*</span> dew<span class="sy0" style="color: rgb(51, 153, 51);">;</span> <span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 东西方向长度(在纬度圈上的投影长度)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">23</span>.		<span class="me1" style="color: rgb(0, 102, 51);">dy</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> DEF_R <span class="sy0" style="color: rgb(51, 153, 51);">*</span> <span class="br0" style="color: rgb(0, 153, 0);">(</span>ns1 <span class="sy0" style="color: rgb(51, 153, 51);">-</span> ns2<span class="br0" style="color: rgb(0, 153, 0);">)</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span> <span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 南北方向长度(在经度圈上的投影长度)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">24</span>.		<span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 勾股定理求斜边长</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">25</span>.		<span class="me1" style="color: rgb(0, 102, 51);">distance</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <a target=_blank style="color: rgb(0, 136, 204); text-decoration: none;" href="http://www.google.com/search?hl=en&q=allinurl%3Amath+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3" style="color: rgb(0, 51, 153);">Math</span></a>.<span class="me1" style="color: rgb(0, 102, 51);">sqrt</span><span class="br0" style="color: rgb(0, 153, 0);">(</span>dx <span class="sy0" style="color: rgb(51, 153, 51);">*</span> dx <span class="sy0" style="color: rgb(51, 153, 51);">+</span> dy <span class="sy0" style="color: rgb(51, 153, 51);">*</span> dy<span class="br0" style="color: rgb(0, 153, 0);">)</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">26</span>.		<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">return</span> distance<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">27</span>.	<span class="br0" style="color: rgb(0, 153, 0);">}</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">28</span>.	<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">public</span> <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> GetLongDistance<span class="br0" style="color: rgb(0, 153, 0);">(</span><span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> lon1, <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> lat1, <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> lon2, <span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> lat2<span class="br0" style="color: rgb(0, 153, 0);">)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">29</span>.	<span class="br0" style="color: rgb(0, 153, 0);">{</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">30</span>.		<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> ew1, ns1, ew2, ns2<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">31</span>.		<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> distance<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">32</span>.		<span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 角度转换为弧度</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">33</span>.		<span class="me1" style="color: rgb(0, 102, 51);">ew1</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> lon1 <span class="sy0" style="color: rgb(51, 153, 51);">*</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">34</span>.		<span class="me1" style="color: rgb(0, 102, 51);">ns1</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> lat1 <span class="sy0" style="color: rgb(51, 153, 51);">*</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">35</span>.		<span class="me1" style="color: rgb(0, 102, 51);">ew2</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> lon2 <span class="sy0" style="color: rgb(51, 153, 51);">*</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">36</span>.		<span class="me1" style="color: rgb(0, 102, 51);">ns2</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> lat2 <span class="sy0" style="color: rgb(51, 153, 51);">*</span> DEF_PI180<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">37</span>.		<span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 求大圆劣弧与球心所夹的角(弧度)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">38</span>.		<span class="me1" style="color: rgb(0, 102, 51);">distance</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <a target=_blank style="color: rgb(0, 136, 204); text-decoration: none;" href="http://www.google.com/search?hl=en&q=allinurl%3Amath+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3" style="color: rgb(0, 51, 153);">Math</span></a>.<span class="me1" style="color: rgb(0, 102, 51);">sin</span><span class="br0" style="color: rgb(0, 153, 0);">(</span>ns1<span class="br0" style="color: rgb(0, 153, 0);">)</span> <span class="sy0" style="color: rgb(51, 153, 51);">*</span> <a target=_blank style="color: rgb(0, 136, 204); text-decoration: none;" href="http://www.google.com/search?hl=en&q=allinurl%3Amath+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3" style="color: rgb(0, 51, 153);">Math</span></a>.<span class="me1" style="color: rgb(0, 102, 51);">sin</span><span class="br0" style="color: rgb(0, 153, 0);">(</span>ns2<span class="br0" style="color: rgb(0, 153, 0);">)</span> <span class="sy0" style="color: rgb(51, 153, 51);">+</span> <a target=_blank style="color: rgb(0, 136, 204); text-decoration: none;" href="http://www.google.com/search?hl=en&q=allinurl%3Amath+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3" style="color: rgb(0, 51, 153);">Math</span></a>.<span class="me1" style="color: rgb(0, 102, 51);">cos</span><span class="br0" style="color: rgb(0, 153, 0);">(</span>ns1<span class="br0" style="color: rgb(0, 153, 0);">)</span> <span class="sy0" style="color: rgb(51, 153, 51);">*</span> <a target=_blank style="color: rgb(0, 136, 204); text-decoration: none;" href="http://www.google.com/search?hl=en&q=allinurl%3Amath+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3" style="color: rgb(0, 51, 153);">Math</span></a>.<span class="me1" style="color: rgb(0, 102, 51);">cos</span><span class="br0" style="color: rgb(0, 153, 0);">(</span>ns2<span class="br0" style="color: rgb(0, 153, 0);">)</span> <span class="sy0" style="color: rgb(51, 153, 51);">*</span> <a target=_blank style="color: rgb(0, 136, 204); text-decoration: none;" href="http://www.google.com/search?hl=en&q=allinurl%3Amath+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3" style="color: rgb(0, 51, 153);">Math</span></a>.<span class="me1" style="color: rgb(0, 102, 51);">cos</span><span class="br0" style="color: rgb(0, 153, 0);">(</span>ew1 <span class="sy0" style="color: rgb(51, 153, 51);">-</span> ew2<span class="br0" style="color: rgb(0, 153, 0);">)</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">39</span>.		<span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 调整到[-1..1]范围内,避免溢出</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">40</span>.		<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">if</span> <span class="br0" style="color: rgb(0, 153, 0);">(</span>distance <span class="sy0" style="color: rgb(51, 153, 51);">></span> <span class="nu0" style="color: rgb(204, 102, 204);">1.0</span><span class="br0" style="color: rgb(0, 153, 0);">)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">41</span>.		     <span class="me1" style="color: rgb(0, 102, 51);">distance</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="nu0" style="color: rgb(204, 102, 204);">1.0</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">42</span>.		<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">else</span> <span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">if</span> <span class="br0" style="color: rgb(0, 153, 0);">(</span>distance <span class="sy0" style="color: rgb(51, 153, 51);"><</span> <span class="sy0" style="color: rgb(51, 153, 51);">-</span><span class="nu0" style="color: rgb(204, 102, 204);">1.0</span><span class="br0" style="color: rgb(0, 153, 0);">)</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">43</span>.		      <span class="me1" style="color: rgb(0, 102, 51);">distance</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="sy0" style="color: rgb(51, 153, 51);">-</span><span class="nu0" style="color: rgb(204, 102, 204);">1.0</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">44</span>.		<span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// 求大圆劣弧长度</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">45</span>.		<span class="me1" style="color: rgb(0, 102, 51);">distance</span> <span class="sy0" style="color: rgb(51, 153, 51);">=</span> DEF_R <span class="sy0" style="color: rgb(51, 153, 51);">*</span> <a target=_blank style="color: rgb(0, 136, 204); text-decoration: none;" href="http://www.google.com/search?hl=en&q=allinurl%3Amath+java.sun.com&btnI=I%27m%20Feeling%20Lucky"><span class="kw3" style="color: rgb(0, 51, 153);">Math</span></a>.<span class="me1" style="color: rgb(0, 102, 51);">acos</span><span class="br0" style="color: rgb(0, 153, 0);">(</span>distance<span class="br0" style="color: rgb(0, 153, 0);">)</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">46</span>.		<span class="kw1" style="color: rgb(0, 0, 0); font-weight: bold;">return</span> distance<span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">47</span>.	<span class="br0" style="color: rgb(0, 153, 0);">}</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">48</span>.	<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> mLat1 <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="nu0" style="color: rgb(204, 102, 204);">39.90923</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span> <span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// point1纬度</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">49</span>.	<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> mLon1 <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="nu0" style="color: rgb(204, 102, 204);">116.357428</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span> <span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// point1经度</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">50</span>.	<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> mLat2 <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="nu0" style="color: rgb(204, 102, 204);">39.90923</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span><span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// point2纬度</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">51</span>.	<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> mLon2 <span class="sy0" style="color: rgb(51, 153, 51);">=</span> <span class="nu0" style="color: rgb(204, 102, 204);">116.397428</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span><span class="co1" style="color: rgb(102, 102, 102); font-style: italic;">// point2经度</span></div></li><li class="li1" style="list-style: none; margin: 0px; padding: 0px; line-height: 21px; vertical-align: top;"><div class="de1"><span class="nu0" style="color: rgb(204, 102, 204);">52</span>.	<span class="kw4" style="color: rgb(0, 0, 102); font-weight: bold;">double</span> distance <span class="sy0" style="color: rgb(51, 153, 51);">=</span> GetShortDistance<span class="br0" style="color: rgb(0, 153, 0);">(</span>mLon1, mLat1, mLon2, mLat2<span class="br0" style="color: rgb(0, 153, 0);">)</span><span class="sy0" style="color: rgb(51, 153, 51);">;</span></div></li></ol>
Python通过百度地图API批量计算两地路线距离(货车路线规划) 阅读详情

相关推荐

Python调用百度地图api获取起点终点路线规划距离和预估时长

现有起点和终点坐标值(经纬度lng、lat),目的是通过百度地图开发者平台的路线规划功能获取起点终点路线规划距离和预估时长,百度地图开发者平台路线规划使用说明网址为:http://lbsyun.baidu.com/index.php?title=webapi/direction-api-abroad 工具:Python3 实现过程并不难,但是爬取过程可能会由于服务器或者参数不满足要求导致爬虫中...

数据之旅的点点滴滴 5万+

百度地图开发:如何计算两点之间距离

 百度地图开发:如何计算两点之间距离   2012-11-26 22:04:27|  分类: 百度地图开发 |  标签:android开发  百度地图开发   |举报 |字号大中小 订阅 路线规划提供了获取路线距离的方法,见MKRoutePlan 类的 getDistance 方法。如果是计算任意两点的距离,有两种方法:一种利用勾股定理计算,适用于两点距离很

codepython的专栏 3084

如何运用Python计算地图上两点的实际距离

作者:xxw9485 时间:2017/6/20 参考资料:参考资料1、参考资料2 之前遇到过这样的问题:手里有一批患者的具体居住地点以及对应的经纬度,我想分析下患者的具体分布情况,不同患者之间的距离关系,这时就需要根据某两点的经纬度来求该两点的实际距离了。下面就是计算公式和代码: 公式 球面上任意两点的距离计算公式可以参考维基百科上的下述文章。 Great-circle...

xxw9485 8994

安卓百度地图计算两点之间的距离--binbinYang

LatLng stare = new LatLng(result.getList().get(i).getLatitude(), result.getList().get(i).getLongitude()); LatLng end = new LatLng(mLat, mLont); double d

binbin 3711

百度地图测量两点距离测算

java版百度地图测量两点之间距离,查看使用方法,原文地址:http://blog.csdn.net/u013271384/article/details/77914778

详解js根据百度地图提供经纬度计算两点距离

正常在使用百度地图时,我们可以通过BMap的实例对象提供的方法计算距离: var map = new BMap.Map('map_canvas'); map.getDistance(point1 ,point2); //point1、point2 是Point对象 如果在不使用百度地图,但是已知百度地图的经纬度情况下也是可以计算出与上面相同的值的 三方库 此库提供计算两点距离的方法 引用此库使用 返回(米) BMapLib.GeoUtils.getDistance(point1 ,point2) 当然如果只想计算距离也可以直接用下面的代码: 注:BMap需要导入,使用如下: BMapLib.

android 百度地图两点之间的距离计算,Android 百度地图 计算两点之间的距离

注:Location类为自定义的实体类,里面包含latitude和longitude两个属性(Double类型)/*** 计算两点之间距离* @param start* @param end* @return 米*/public Double getDistance(Location start,Location end){double lat1 = (Math.PI/180)*start.get...

weixin_42499335的博客 811

Polars简明基础教程一:Polars快速入门

在这个例子中,我们将添加一个列,其中包含每个舱位中乘客的最大年龄。在Python中(而不是特指Polars),当我们将代码包裹在括号中时,我们可以在新行上调用一个新方法——在这种情况下是select。在这里,我们看到一个使用表达式API的简单示例,其中我们在select语句中选择Pclass、Name和Age列(我们将在第3节中深入了解select语句)。表达式是一个函数,它接受一个Series(或DataFrame中的列)作为输入,并返回一个Series(或DataFrame中的列)。

sosogod的博客 3885

百度地图计算两点之间的距离

转至 http://blog.csdn.net/chentravelling/article/details/51058742 /** * 计算两点之间距离 * @param start * @param end * @return 米 */ public String getDistance(LatLng start,LatLng end){ double lat1 = (M

hello_Ya的博客 7174

双足步行机器人的ZMP与CoP检测

静态步行与动态步行   机器人步态分为静态步行和动态步行。当机器人做静态步行运动时,身体的各个部分运动速度很小,机器人的整体稳定性较易控制。静态步行稳定性采用机器人的重心地面投影点(Center of Gravity,简称CoG)作为稳定性标准,这种判定方法适用于运动较为缓慢的情况。如果机器人采用的是一种高速运动的步行方式,则称之为动态步行。当机器人进行动态步行时,其重心的位置和加速度的大小时...

weixin_34112208的博客 5923

ADS负载牵引仿真避坑指南:从零开始搞定Loadpull模板设置

本文是一份针对ADS负载牵引仿真的深度避坑指南,详细解析了Loadpull模板从初始化配置到结果解读的全过程。文章重点阐述了如何根据设计目标灵活设置扫描圆、采样点等关键参数,以解决仿真不收敛、结果不完整等常见问题,并指导读者在功率与效率之间做出理性权衡,最终提取出用于匹配网络设计的最优负载阻抗。

weixin_29234423的博客 602

百度地图实现计算两点之间的距离

**百度地图开发:如何计算两点之间距离路线规划提供了获取路线距离的方法,见MKRoutePlan 类的 getDistance 方法。如果是计算任意两点的距离,有两种方法:一种利用勾股定理计算,适用于两点距离很近的情况;一种按标准的球面大圆劣弧长度计算,适用于距离较远的情况。 1. static double DEF_PI = 3.14159265359; // PI 2. static dou

han478270575的博客 1877

AF驱动调试日志全解析:从配置到问题排查

本文全面解析AF驱动调试日志的配置、抓取与分析方法。从内核驱动与HAL层配置入手,确保日志正常输出,并详细解读开机初始化、马达识别、I2C通信等关键日志节点。通过多个实战案例,如对焦失败、前摄无功能、参数不生效及I2C报错等,系统性地展示了如何利用日志定位并解决AF对焦问题,是摄像头模组开发与调试的实用指南。

weixin_28285943的博客 311

百度地图计算两点之间距离

路线规划提供了获取路线距离的方法,见MKRoutePlan 类的 getDistance 方法。 如果是计算任意两点的距离,自2.0.0版本开始,Android SDK为开发者提供了计算距离的接口(DistanceUtil),具体使用方法如下: 1.GeoPoint p1LL = new GeoPoint(39971802, 116347927); 2.GeoPoint p2LL

u013363974的专栏 2159

CATIA CAA开发环境搭建避坑指南:从授权服务到VS配置全流程

本文提供了一份详尽的CATIA CAA开发环境搭建避坑指南,涵盖从授权服务(DSLS)安装、Visual Studio版本匹配与集成配置,到编译调试全流程。重点解析了授权服务无法连接、模块加载失败等典型问题的解决方案,强调版本严格对应与纯英文环境是成功搭建的关键。

redis7keeper的博客 591

IP路由原理、静态路由及动态路由区分

什么是路由 路由是指导IP报文发送的路径信息。 直连路由:目的地所在网络与路由器直接相连。 间接路由:目的地所在网络与路由器非直接相连。 静态路由是由管理员手工配置而生成的路由。 动态路由路由器使用路由协议从其他路由器那里获悉的路由。

weixin_42227328的博客 5477

php百度地图距离排序,百度地图计算两点之间距离

路线规划提供了获取路线距离的方法,见MKRoutePlan 类的 getDistance 方法。如果是计算任意两点的距离,自2.0.0版本开始,Android SDK为开发者提供了计算距离的接口(DistanceUtil),具体使用方法如下:1.GeoPoint p1LL = new GeoPoint(39971802, 116347927);2.GeoPoint p2LL = new GeoPo...

weixin_35452206的博客 335

一文吃透 SAP HANA Service Broker:原理、架构与落地实践

摘要:SAP HANA Service Broker 作为云原生开发的关键组件,通过标准化流程管理 HDI 容器与服务实例的生命周期,实现数据库资源的自动化配置与安全隔离。它采用服务目录、服务计划和绑定机制,将连接凭据注入应用环境变量,避免硬编码风险。在实际应用中,需根据模块生命周期决定共享或隔离容器,并通过跨容器访问模式实现安全数据共享。典型案例展示了电商平台的多模块协同与SaaS租户隔离场景,验证了其在提升运维效率与安全合规方面的价值。最佳实践强调以生命周期划边界、最小权限原则和HTTPS安全传输,为企

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 234

Android 百度地图 计算两点之间的距离

注:Location类为自定义的实体类,里面包含latitude和longitude两个属性(Double类型) /** * 计算两点之间距离 * @param start * @param end * @return 米 */ public Double getDistance(Location start,Location end){ double lat1 = (Mat...

qq910441958的博客 2738

ROSTEA软件下载及情感分析详细操作教程(附网盘链接)

原ROST虚拟团队出品的ROST系列文本内容挖掘分析平台,是辅助人文社会科学研究的免费计算平台。该软件可以实现文本预处理、分字、分词、词性识别、特殊名词抽取、词频统计、英文词频统计、情感计算、分类算法、聚类算法等一系列文本挖掘,是人文社科研究和论文写作的一把利器。该软件用户量超过一万人,遍布海内外100多所大学,包括剑桥大学、日本北海道大学、北京大学、清华大学、香港城市大学、澳门大学等众多高校。关于ROSTCM6的安装介绍可以参考之前的文章ROSTCM6软件下载及语义网络分析详细操作教程ROST EA。

m0_64336780的博客 1万+

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

上一篇: 【百度地图API】如何根据摩卡托坐标进行POI查询,和计算两点距离
下一篇: Android中使用代码截图的各种方法总结
codepython
博客等级 码龄20年 125粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址