1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
'exemple https://maps.googleapis.com/maps/api/distancematrix/json?origins=toulon&destinations=paris&sensor=false"
Sub test()
donnéegooglemaps "trucmuche", "paris"
End Sub
Function donnéegooglemaps(depart, arrivée)
Dim DemandeFichier As Object, distance As String, durrée As String, url As String, message As String
url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=" & depart & "&destinations=" & arrivée & "&sensor=false"
Set DemandeFichier = CreateObject("Microsoft.XMLHTTP") 'instancie l'object
DemandeFichier.Open "POST", url, False
DemandeFichier.send
' MsgBox DemandeFichier.responsetext 'ce message t'affiche tout le texte en entier
If InStr(DemandeFichier.responsetext, "NOT_FOUND") > 0 Then
message = "pas de donnée pour ce parcour " & vbCrLf & " veuillez verifier le depart ou destination"
Else
distance = Split(Split(DemandeFichier.responsetext, "text"" : ")(1), ",")(0)
durrée = Split(Split(DemandeFichier.responsetext, "text"" : ")(2), ",")(0)
message = "disitance a parcourir = " & distance & vbCrLf & "durée du voyage = " & durrée
End If
MsgBox message
End Function |
Partager