Foxtable(狐表)用户栏目专家坐堂 → 两个地址间的驾车距离


  共有3634人关注过本帖树形打印复制链接

主题:两个地址间的驾车距离

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By: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)


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/4/14 20:06:00 [显示全部帖子]

 上传具体例子,方法已经在2楼给出。

 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/4/14 21:01:00 [显示全部帖子]

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


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By: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


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By: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


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/4/15 9:45:00 [显示全部帖子]

直接查也可以

 

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 address as string = "http://api.map.baidu.com/direction?origin=latlng:" & lat1 & "," & lng1 & "|name:" & 起点 & "&destination=latlng:" & lat2 & "," & lng2 & "|name:" & 终点 & "&mode=driving&region=西安&output=html&src=yourCompanyName|yourAppName"

Dim web As new windows.forms.webbrowser
web.Navigate(address)
Do Until web.ReadyState = 4
     Application.DoEvents
Loop

'output.show(web.document.body.innerhtml)

Dim result As String = web.Document.GetElementById("navDis").InnerText
msgbox(result)


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/4/15 14:03:00 [显示全部帖子]

我测试,没,问,题

 

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 address As String = "http://api.map.baidu.com/direction?origin=latlng:" & lat1 & "," & lng1 & "|name:" & 起点 & "&destination=latlng:" & lat2 & "," & lng2 & "|name:" & 终点 & "&mode=driving&region=西安&output=html&src=yourCompanyName|yourAppName"

Dim web As new windows.forms.webbrowser
web.Navigate(address)
Do Until web.ReadyState = 4
    Application.DoEvents
Loop

'output.show(web.document.body.innerhtml)
If web.Document.GetElementById("navDis") Is Nothing Then
    msgbox("没查到")
Else
    Dim result As String = web.Document.GetElementById("navDis").InnerText
    msgbox(result)
end if


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/4/18 0:27:00 [显示全部帖子]

以下是引用liu_songsong在2016/4/16 10:00:00的发言:
大红袍 老师,经测试,有些可以有些不可以,是否哪里可以改进。
例子在15楼

 

地址过于简单、或者过于详细,都是不能查询的。

 

比如 松江区有歧义,哪个城市的?

 

比如 809室 不是地址,没必要写。


 回到顶部