Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

J'ai fait ça ce matin

1 réponse
Avatar
mriquelyon
petites fonctions qui calculent les temps de trajet et distance par la
route (google maps) entre deux villes ou code postaux
le genre de truc =E0 garder dans un coin qui sert tjrs un jour... et si
vous avez des id=E9es d'am=E9lioration...

Function get_km(place_a, place_b)
my_xml_path =3D "http://maps.google.fr/maps?saddr=3D" & place_a &
"&daddr=3D" & place_b & "&ie=3Dutf-8&v=3D2.1&cv=3D4.0.2744&hl=3Dfr&output=
=3Dkml"
Set xmlDoc =3D CreateObject("MSXML2.DOMDocument")
xmlDoc.async =3D False
xmlDoc.Load (my_xml_path)
Set nodelist =3D xmlDoc.getElementsByTagName("description")
my_raw_string =3D nodelist.Item(nodelist.Length -
1).firstchild.nodevalue
get_km =3D Monextract(my_raw_string, ": ", "&")
End Function

Function get_driving_time(place_a, place_b)
my_xml_path =3D "http://maps.google.fr/maps?saddr=3D" & place_a &
"&daddr=3D" & place_b & "&ie=3Dutf-8&v=3D2.1&cv=3D4.0.2744&hl=3Dfr&output=
=3Dkml"
Set xmlDoc =3D CreateObject("MSXML2.DOMDocument")
xmlDoc.async =3D False
xmlDoc.Load (my_xml_path)
Set nodelist =3D xmlDoc.getElementsByTagName("description")
my_raw_string =3D nodelist.Item(nodelist.Length -
1).firstchild.nodevalue
get_driving_time =3D Monextract(my_raw_string, "environ ", ")")
get_driving_time =3D Replace(get_driving_time, "minutes", "")
If InStr(get_driving_time, "heure") =3D 0 Then get_driving_time =3D "00:"
& get_driving_time
get_driving_time =3D Replace(get_driving_time, "heures", ":")
get_driving_time =3D Replace(get_driving_time, "heure", ":")
get_driving_time =3D get_driving_time & ":00"
get_driving_time =3D Replace(get_driving_time, " ", "")
get_driving_time =3D TimeValue(get_driving_time)
End Function

Function Monextract(machaine, debut, fin)
PosH1 =3D InStr(1, machaine, debut)
PosH2 =3D InStr(1, machaine, fin)
long_first =3D Len(debut)
Leng =3D PosH2 - PosH1 - long_first
Monextract =3D Mid(machaine, PosH1 + long_first, Leng)
End Function

1 réponse

Avatar
Misange
Tu fais des choses sympas le matin :-)
et le soir ça donne quoi ?
Tu ne voudrais pas mettre tout ça dans un classeur exemple et le
proposer en téléchargement sur excelabo pour pérenniser ton travail ?
Si oui, l'adresse pour le proposer c'est là :
http://www.excelabo.net/moteurs/contribuer.php
ce serait avec plaisir.

Misange migrateuse
XlWiki : Participez à un travail collaboratif sur excel !
http://xlwiki.free.fr/wiki
http://www.excelabo.net

petites fonctions qui calculent les temps de trajet et distance par la
route (google maps) entre deux villes ou code postaux
le genre de truc à garder dans un coin qui sert tjrs un jour... et si
vous avez des idées d'amélioration...

Function get_km(place_a, place_b)
my_xml_path = "http://maps.google.fr/maps?saddr=" & place_a &
"&daddr=" & place_b & "&ie=utf-8&v=2.1&cv=4.0.2744&hl=fr&output=kml"
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmlDoc.Load (my_xml_path)
Set nodelist = xmlDoc.getElementsByTagName("description")
my_raw_string = nodelist.Item(nodelist.Length -
1).firstchild.nodevalue
get_km = Monextract(my_raw_string, ": ", "&")
End Function

Function get_driving_time(place_a, place_b)
my_xml_path = "http://maps.google.fr/maps?saddr=" & place_a &
"&daddr=" & place_b & "&ie=utf-8&v=2.1&cv=4.0.2744&hl=fr&output=kml"
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmlDoc.Load (my_xml_path)
Set nodelist = xmlDoc.getElementsByTagName("description")
my_raw_string = nodelist.Item(nodelist.Length -
1).firstchild.nodevalue
get_driving_time = Monextract(my_raw_string, "environ ", ")")
get_driving_time = Replace(get_driving_time, "minutes", "")
If InStr(get_driving_time, "heure") = 0 Then get_driving_time = "00:"
& get_driving_time
get_driving_time = Replace(get_driving_time, "heures", ":")
get_driving_time = Replace(get_driving_time, "heure", ":")
get_driving_time = get_driving_time & ":00"
get_driving_time = Replace(get_driving_time, " ", "")
get_driving_time = TimeValue(get_driving_time)
End Function

Function Monextract(machaine, debut, fin)
PosH1 = InStr(1, machaine, debut)
PosH2 = InStr(1, machaine, fin)
long_first = Len(debut)
Leng = PosH2 - PosH1 - long_first
Monextract = Mid(machaine, PosH1 + long_first, Leng)
End Function