#include "FiveWin.ch"
static oDlg,cOrigen:="",cDestino:="",cTextoHTML:="",nDistancia:=0,cTiempo:=""
static oGet1,oGet2,oBtn1,oBtn2,nSeg:=0
function main()
set exact on
set date french
set century on
cOrigen:=left("Madrid, Spain"+space(255),255)
cDestino:=left("Paris, France"+space(255),255)
oHttp:=CreateObject("winhttp.winhttprequest.5.1")
DEFINE DIALOG oDlg TITLE "Calculador de distancias por carretera"
@ 1, 2 SAY "Origen" OF oDlg
@ 1, 5 GET oGet1 VAR cOrigen OF oDlg SIZE 90, 10 PICTURE replicate("X",255)
@ 1.8,2 SAY "Destino" OF oDlg
@ 2, 5 GET oGet2 VAR cDestino OF oDlg SIZE 90, 10 PICTURE replicate("X",255)
@ 3, 7 BUTTON oBtn1 PROMPT "&Ok" SIZE 30, 12 OF oDlg ACTION Calcular()
@ 3, 16 BUTTON oBtn2 PROMPT "&Cancelar" SIZE 30, 12 OF oDlg ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED
return nil
function Calcular()
local Aux,Aux1
nSeg:=seconds()
CursorWait()
oGet1:Disable()
oGet2:Disable()
oBtn1:Disable()
oBtn2:Disable()
Try
oHttp:SetTimeouts(30000,30000,30000,30000)
oHttp:Open("GET","http://maps.google.es/maps?saddr="+alltrim(cOrigen)+"&daddr="+alltrim(cDestino),.F.)
oHttp:Send()
cTextoHTML:=oHttp:ResponseText()
Catch
cTextoHTML:="Error"
End Try
// Buscar una cadena de este tipo "<div><b>702 km</b> – aprox. <b>6h 48 min</b></div>"
Aux:=" km</b>"
if .not. Aux $ cTextoHTML
CursorArrow()
MsgInfo("Imposible calcular distancia","Informacion")
oGet1:Enable()
oGet2:Enable()
oBtn1:Enable()
oBtn2:Enable()
return nil
endif
cTextoHTML:=substr(cTextoHTML,at(Aux,cTextoHTML)-25)
Aux:="<div>"
cTextoHTML:=substr(cTextoHTML,at(Aux,cTextoHTML))
Aux:="</div>"
cTextoHTML:=left(cTextoHTML,at(Aux,cTextoHTML)+len(Aux)-1)
Aux:="<div><b>"
Aux1:=substr(cTextoHTML,at(Aux,cTextoHTML)+len(Aux))
Aux:=" km"
Aux1:=left(Aux1,at(Aux,Aux1)+len(Aux)-1)
do while "." $ Aux1 // Quita los PUNTOS
Aux1:=stuff(Aux1,at(".",Aux1),1,"")
enddo
nDistancia:=val(Aux1)
Aux:="</b> – aprox. <b>"
Aux1:=substr(cTextoHTML,at(Aux,cTextoHTML)+len(Aux))
Aux:="</b></div>"
Aux1:=left(Aux1,at(Aux,Aux1)-1)
cTiempo:=Aux1
CursorArrow()
MsgInfo("De "+chr(34)+upper(alltrim(cOrigen))+chr(34)+;
" a " +chr(34)+upper(alltrim(cDestino))+chr(34)+;
" hay "+alltrim(str(nDistancia))+" km."+chr(13)+;
"Tiempo por carretera "+cTiempo,;
"Informacion ("+alltrim(str(seconds()-nSeg,5,1))+"seg.)")
oGet1:Enable()
oGet2:Enable()
oBtn1:Enable()
oBtn2:Enable()
return nil