2013-07-21 4 views
0

Je travaille sur un projet où je veux afficher une carte google dans un objet WebBrowser sur une feuille Excel. J'ai accompli cela en utilisant cette URL ....Google Maps Directions Only

http://maps.google.com/?saddr=29.9390146,-90.0696139&daddr=29.962506,-90.1930133&f=d&output=embed

Je voudrais également afficher les directions de conduite uniquement pour ce même lien (ou un autre).

Je ne trouve aucune information sur la façon d'obtenir google maps pour retourner les directions seulement via l'URL.

AHIA, LarryR

Répondre

1

Vous voulez vérifier l'Api GoogleMaps:

Static Map API

Directions API

Ces API vous fournit une réponse XML où vous pouvez les analyser pour obtenir les résultats affichés. J'ai fait un pour trouver le temps et la distance que vous pouvez utiliser comme exemple: Ceci est l'une de mes précédentes tentatives donc pas de XML est utilisé mais il vous donnera une idée de comment travailler avec les réponses de google.

Public Function GMap(origin_address As String, destination_address As String, Optional mode As Integer = 1, Optional datatype As Integer = 1) 

Dim surl As String 
Dim oXH As Object 
Dim bodytxt As String 
Dim time_e As String 
Dim distanc_e As String 
Dim strmode As String 

If mode = 1 Then 
    strmode = "walking" 
ElseIf mode = 2 Then 
    strmode = "driving" 
ElseIf mode = 3 Then 
    strmode = "bicycling" 
Else 
    GMap = "Invalid Mode" 
    Exit Function 
End If 

surl = "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=;" & _ 
Replace(origin_address, " ", "+") & "&destinations=" & Replace(destination_address, " ", "+") & _ 
"&mode=" & strmode & "&sensor=false&units=metric" 

Set oXH = CreateObject("msxml2.xmlhttp") 

With oXH 
    .Open "get", surl, False 
    .send 
    bodytxt = .responseText 
End With 

bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5) 
tim_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1) 
bodytxt = Right(bodytxt, Len(bodytxt) - InStr(1, bodytxt, "<text>") - 5) 
distanc_e = Left(bodytxt, InStr(1, bodytxt, "</text>") - 1) 

If datatype = 1 Then 
    GMap = CDbl(Replace(tim_e, "mins", "")) 
ElseIf datatype = 2 Then 
    GMap = CDbl(Replace(distanc_e, "km", "")) 
Else 
    GMap = "Invalid Data" 
End If 

Set oXH = Nothing 
End Function 
Questions connexes