1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| '#######################################
'### Pour le Early Binding
'### nécessite la référence
'### Library MSXML2
'### C:\WINDOWS\system32\msxml2.dll
'### Microsoft XML, v2.6
'#######################################
Function PointGeodesique(Plage_AdresseCodeVillePays As Range) As String
Dim XmlH As Object '(Late Binding) MSXML2.XMLHTTP
Dim C As Range
Dim Url$
Dim A$
Dim Latitude$
Dim Longitude$
'--- Chaîne des paramètres ---
For Each C In Plage_AdresseCodeVillePays
If Trim(C) <> "" Then
Url$ = Replace(Trim(C), Space(1), "+") & ",+"
End If
Next C
Url$ = Url$ & "&sensor=false"
'--- GoogleAPIs ---
Url$ = "http://maps.googleapis.com/maps/api/geocode/xml?address=" & Url$
'--- MSXML2.XMLHTTP ---
Set XmlH = CreateObject("msxml2.xmlhttp")
With XmlH
.Open "get", Url$, False
.Send
A$ = Trim(.responseText)
End With
'--- Latitude et longitude ---
Latitude$ = Right(A$, Len(A$) - InStr(1, A$, "<lat>") - 4)
Latitude$ = Left(Latitude$, InStr(1, Latitude$, "</lat>") - 1)
Longitude$ = Right(A$, Len(A$) - InStr(1, A$, "<lng>") - 4)
Longitude$ = Left(Longitude$, InStr(1, Longitude$, "</lng>") - 1)
'--- Retour ---
PointGeodesique = "Latitude:" & Latitude$ & " Longitude:" & Longitude$
End Function |
Partager