Notifications
Clear all

Calcular KM baseado em CEP

2 Posts
1 Usuários
0 Reactions
682 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Senhores,

Vi um post sobre isso, o problema é q baixo os arquivos para tentar analisar e resolver minha demanda e os arquivos do topico estão corrompidos.

Alguém pode me dar um Help?

Usei esse código q peguei na internet, mas não funciona, sempre retorna 0 KM

Antecipo agradecimentos,

Wenceslau

Function G_DISTANCIA(Origin As String, Destination As String)
' Requires a reference to Microsoft XML, v6.0
' Draws on the stackoverflow answer at bit.ly/parseXML
Dim myRequest As XMLHTTP60
Dim myDomDoc As DOMDocument60
Dim distanceNode As IXMLDOMNode
G_DISTANCIA = 0
' Check and clean inputs
On Error GoTo exitRoute
Origin = Replace(Origin, " ", "%20")
Destination = Replace(Destination, " ", "%20")

' Read the XML data from the Google Maps API
Set myRequest = New XMLHTTP60
myRequest.Open "GET", " http://maps.googleapis.com/maps/api/directions/xml?origin=" _
& Origin & "&destination=" & Destination & "&sensor=false", False
myRequest.send
' Make the XML readable usign XPath
Set myDomDoc = New DOMDocument60
myDomDoc.LoadXML myRequest.responseText
' Get the distance node value
Set distanceNode = myDomDoc.SelectSingleNode("//leg/distance/value")

If Not distanceNode Is Nothing Then G_DISTANCIA = (distanceNode.Text / 1000) & " KM"
exitRoute:
' Tidy up
Set distanceNode = Nothing
Set myDomDoc = Nothing
Set myRequest = Nothing
End Function

 
Postado : 29/09/2014 11:08 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Boa tarde!

Você ativou o Microsoft XML, v6.0?
Digite os CEPs no seguinte formato: xxxxx-xxx (18160-000)

[]Doni

 
Postado : 29/09/2014 12:16 pm