Google Distance Matrix API Key Excel VBA

大憨熊 提交于 2019-12-10 11:37:50

问题


I can't get the VBA Code in my Excel Document to connect to my account, using the API Key. Not sure if I'm putting the key in the right place. I've even upgraded my account, and have billing Enabled. I'm trying to pay them, but it wont let me exceed 2,500 transactions. Thanks in advance for the help.

Edit (7/20):
So I updated my code to use ClientID instead of API key '&clientid=EntersIDHere' and it works, but still only does 2500 transactions.

'Calculate Google Maps distance between two addresses
Public Function GetDistance(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=en-US&clientid=EntersKeyHere"
    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, """distance"" : {") = 0 Then GoTo ErrorHandl
    Set regex = CreateObject("VBScript.RegExp"): regex.Pattern = """value"".*?([0-9]+)": regex.Global = False
    Set matches = regex.Execute(objHTTP.responseText)
    tmpVal = Replace(matches(0).SubMatches(0), ".", Application.International(xlListSeparator))
    GetDistance = CDbl(tmpVal)
    Exit Function
ErrorHandl:
    GetDistance = -1
End Function

来源:https://stackoverflow.com/questions/38485353/google-distance-matrix-api-key-excel-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!