Question: How do I incorporate my own API Key into the google code below? 'Calculate Google Maps distance between two addresses Public Function GetDistance(start As String,

How do I incorporate my own API Key into the google code below?

'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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!