对于时间和距离数据谷歌地图API(接入/ VBA) [英] Google Maps API for Time and Distance Data (Access/VBA)
问题描述
我有一个应用程序,这将是非常有益的,以便能够 从谷歌获得直接映射的时间和里程(行驶里程) 之间的两个地址。我已经通过许多网站犁和 文件和完全foxed至于如何做到这一点。
I have an application where it would be highly beneficial to be able to get directly from google maps the time and miles (driving miles) between two addresses. I have plowed through many web sites and documents and totally foxed as to how to do it.
有没有人做出与谷歌地图API连接成功 微软方法和提取的时间和距离信息?如果 有邻他们能分享他们使用了code。
Has anyone made a successful connection with google maps API using Microsoft Approach and extracted time and distance information? If have, o could they share the code they used.
我想建立一个驱动程序调度系统的志愿者 驱动程序组(驾驶人禾预约就诊谁不能 开车,买不起出租车,买不起车!)。
I am trying to set up a driver scheduling system for a volunteer drivers group (driving for people wo medical appointments who cannot drive, cannot afford taxies and cannot afford cars!).
任何帮助将AP preciated
Any help would be appreciated
约翰·贝克
推荐答案
下面是一些code做你想做的事情。一定要明白,谷歌确实对使用其API的一些许可要求/限制。你应该使用这里在谷歌地图获得的结果。请阅读使用限制在这里:<一href="https://developers.google.com/maps/documentation/directions/">https://developers.google.com/maps/documentation/directions/
Here's some code to do what you want to do. Do realize that Google does have some licensing requirements/limitations on using their API. You are supposed to use the results obtained here in a Google Map. Please read the Usage Limitations here: https://developers.google.com/maps/documentation/directions/
请注意,这需要一提到微软XML,6.0版,除非你改变了code使用后期绑定。
Note that this requires a reference to "Microsoft XML, v6.0" unless you change the code to use late binding.
Dim sXMLURL As String
sXMLURL = "http://maps.googleapis.com/maps/api/directions/xml?origin=NY,+NY&destination=Los+Angeles,+CA&sensor=false"
Dim objXMLHTTP As MSXML2.ServerXMLHTTP
Set objXMLHTTP = New MSXML2.ServerXMLHTTP
With objXMLHTTP
.Open "GET", sXMLURL, False
.setRequestHeader "Content-Type", "application/x-www-form-URLEncoded"
.Send
End With
'Debug.Print objXMLHTTP.ResponseText
Dim domResponse as DOMDocument60
Set domResponse = New DOMDocument60
domResponse.loadXML objXMLHTTP.ResponseText
Dim ixnStatus
Set ixnStatus = domResponse.selectSingleNode("//status")
If ixnStatus.Text = "OK" Then
Dim ixnDistance, ixnDuration
Set ixnDistance = domResponse.selectSingleNode("/DirectionsResponse/route/leg/distance/text")
Set ixnDuration = domResponse.selectSingleNode("/DirectionsResponse/route/leg/duration/text")
Debug.Print "Distance: " & ixnDistance.Text 'Miles
Debug.Print "Duration: " & ixnDuration.Text 'Days Hours Minutes
End If
Set domResponse = Nothing
Set objXMLHTTP = Nothing
我特意选择使用XML而不是JSON,因为VBA是不是太方便使用JSON,也不是一,有您可以下载通常被称为VBJSON一个模块,但它有一个小的学习曲线,尤其是当你从来没有使用JSON工作过。我相信XML是更贵(低效率),但我认为这也更容易在访问VBA工作。
I've intentionally chosen to use XML instead of JSON because VBA is not overly handy with JSON, and neither am I. There is a module you can download often referred to as VBJSON but it has a little learning curve, especially if you never worked with JSON before. I believe XML is more "expensive" (less efficient) but I think it's also easier to work with in Access VBA.
这篇关于对于时间和距离数据谷歌地图API(接入/ VBA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!