我在Excel中有一组邮政编码对。我的目标是使用Google Maps API或任何其他优质来源,并获得每对邮政编码之间的行车距离。这可能吗?如果这些数据点位于SQL Server表中,是否有办法使用SSIS Web服务任务执行此操作?
我想了解如何做到最好。我查看了Google Distance Matrix API,但明确提到严禁在非Google地图使用中使用该API。
提前感谢您指导我如何设计它。
答案 0 :(得分:1)
分析师洞穴在使用Google API方面做了很好的准备: http://www.analystcave.com/excel-calculate-distances-between-addresses/
Public Function GetDuration(start As String, dest As String)
Dim firstVal As String, secondVal As String, lastVal As String
firstVal = "http://maps.googleapis.com/maps/api/distancematrix/json?origins="
secondVal = "&destinations="
lastVal = "&mode=car&language=pl&sensor=false"
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = firstVal & Replace(start, " ", "+") & secondVal & Replace(dest, " ", "+") & lastVal
objHTTP.Open "GET", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("")
If InStr(objHTTP.responseText, """duration"" : {") = 0 Then GoTo ErrorHandl
tmpVal = Right(objHTTP.responseText, Len(objHTTP.responseText) - InStr(objHTTP.responseText, """duration"" : {") - Len("""duration"" : {"))
tmpVal = Right(tmpVal, Len(tmpVal) - InStr(tmpVal, """value"" : ") - Len("""value"" :"))
tmpVal = Left(tmpVal, InStr(tmpVal, "}") - 1): tmpVal = Replace(tmpVal, ".", ",")
GetDuration = CLng(Replace(tmpVal, ",", ""))
Exit Function
ErrorHandl:
GetDuration = -1
End Function
然后,您可以使用Google API查找更多参数:
https://developers.google.com/maps/documentation/distancematrix/#JSON