以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  两个地址间的驾车距离  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=83701)

--  作者:liu_songsong
--  发布时间:2016/4/14 19:41:00
--  两个地址间的驾车距离
能否获取两个地址间的驾车距离?
--  作者:大红袍
--  发布时间:2016/4/14 19:44:00
--  

x1、y1 是纬度、经度

 

Dim x1 As Double = 37.856862
Dim y1 As Double = 112.525760
Dim x2 As Double = 37.857587
Dim y2 As Double = 112.525683


Dim rad As Double = 6371
Dim p1X As Double = X1 / 180 * Math.PI
Dim p1Y As Double = Y2 / 180 * Math.PI
Dim p2X As Double = X2 / 180 * Math.PI
Dim p2Y As Double = Y2 / 180 * Math.PI

Dim a As Double = p1X - p2X
Dim b As Double = p1Y - p2Y
Dim s As Double = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a/2),2) + Math.Cos(p1X)*Math.Cos(p2X)*Math.Pow(Math.Sin(b/2),2))) * rad
output.show(s)


--  作者:liu_songsong
--  发布时间:2016/4/14 20:04:00
--  
感谢老师的回复。
1、按照上面计算的是直线距离还是按照驾车路线计算的距离,我需要计算驾车路线距离
2、地址的坐标也需要通过地址来获取
具体表格如下:
 提货地址    送货地址  驾车距离  
   上海   广州   需要计算


--  作者:大红袍
--  发布时间:2016/4/14 20:06:00
--  
 上传具体例子,方法已经在2楼给出。
--  作者:liu_songsong
--  发布时间:2016/4/14 20:45:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:距离.table


--  作者:大红袍
--  发布时间:2016/4/14 21:01:00
--  

 没有坐标、没有线路怎么可能计算啊


--  作者:liu_songsong
--  发布时间:2016/4/14 21:44:00
--  
能不能根据地址计算坐标和路线
--  作者:大红袍
--  发布时间:2016/4/14 21:57:00
--  

mark 获取坐标,两点线路

 

Dim 起点 As String = "天津市西青区西青道三星路1号"
Dim 终点 As String = "青岛市敦化路22号"

Dim rqst As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://api.map.baidu.com/geocoder/v2/?address=" & 起点 & "&output=json&ak=hAaa2NLELKdAIfMhMjnuEgi1")
Dim rsps As System.Net.HttpWebResponse = rqst.GetResponse
Dim stm As System.IO.Stream = rsps.GetResponseStream()
Dim reader As New System.IO.StreamReader(stm)
Dim json As String = reader.ReadToEnd
\'msgbox(json)
Dim ScriptControl As Object, data  As Object, JscriptCode As String
JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", json)
End With

Dim lng1 = data.result.location.lng
Dim lat1 = data.result.location.lat

 

 

rqst  = System.Net.HttpWebRequest.Create("http://api.map.baidu.com/geocoder/v2/?address=" & 终点 & "&output=json&ak=hAaa2NLELKdAIfMhMjnuEgi1")
rsps = rqst.GetResponse
stm = rsps.GetResponseStream()
reader = New System.IO.StreamReader(stm)
json = reader.ReadToEnd
\'msgbox(json)

JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}"
ScriptControl = CreateObject("MSScriptControl.ScriptControl")
With ScriptControl
    .Language = "Javascript"
    .Timeout = -1
    .AddCode(JscriptCode)
    data = .Run("toObject", json)
End With

Dim lng2 = data.result.location.lng
Dim lat2 = data.result.location.lat

 

Dim proc As new Process
proc.file = "http://api.map.baidu.com/direction?origin=latlng:" & lat1 & "," & lng1 & "|name:" & 起点 & "&destination=latlng:" & lat2 & "," & lng2 & "|name:" & 终点 & "&mode=driving&region=西安&output=html&src=yourCompanyName|yourAppName"
\'output.show(proc.file)
proc.start


--  作者:大红袍
--  发布时间:2016/4/14 21:58:00
--  

简单一点就这样

 

Dim 起点 As String = "天津市西青区西青道三星路1号"
Dim 终点 As String = "青岛市敦化路22号"
Dim proc As new Process
proc.file = "http://api.map.baidu.com/direction?origin=" & 起点 & "&destination=" & 终点 & "&mode=driving&region=西安&output=html&src=yourCompanyName|yourAppName"
output.show(proc.file)
proc.start


--  作者:liu_songsong
--  发布时间:2016/4/15 9:05:00
--  
感谢大红袍老师