TUNCA ERSİN
Altın Üye
- Katılım
- 18 Ağustos 2021
- Mesajlar
- 131
- Excel Vers. ve Dili
- Office Professional plus 2016 Tr
DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
Altın Üyelik Hakkında Bilgi
Sub CalculateDistance()
Dim startLocation As String
Dim endLocation As String
Dim apiKey As String
Dim url As String
Dim xmlHttp As Object
Dim responseText As String
Dim distance As String
startLocation = Sheets("Sheet1").Range("A1").Value
endLocation = Sheets("Sheet1").Range("B1").Value
apiKey = "Buraya API anahtarınızı gireceksiniz"
url = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & _
Replace(startLocation, " ", "+") & _
"&destinations=" & _
Replace(endLocation, " ", "+") & _
"&key=" & apiKey
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "GET", url, False
xmlHttp.send
responseText = xmlHttp.responseText
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = "<distance>(.*?)<\/distance>"
Set matches = regex.Execute(responseText)
If matches.Count > 0 Then
distance = matches(0).SubMatches(0)
Sheets("Sheet1").Range("C1").Value = distance
Else
MsgBox "Mesafe bilgisi alınamadı."
End If
End Sub