voici mon script qui permet de connaître une adresse à partir d'une latitude et d'une longitude:
Dans ce premier exemple, j'ai le sentiment que mon problème pourrait être au niveau des ActiveX autorisés ou pas car ma page html utilise les activeX pour créer un fichier de sauvegarde
► Afficher le texte
Code : Tout sélectionner
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=latlonToAdress.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>
#include <IE.au3>
CreateHtml()
$url = @TempDir & "\reverse_geocoding.html"
$lat = 40.730885
$lon = -73.997383
$ie= _IECreate ($url,1,0,1)
_ReplaceStringInFile($url, "LATITUDE", $lat, 1, 0) ;Paramètre 1 = Sensible a la casse || Paramètre 0 = Remplace le premier trouvé
_ReplaceStringInFile($url, "LONGITUDE", $lon, 1, 0) ;Paramètre 1 = Sensible a la casse || Paramètre 0 = Remplace le premier trouvé
_IENavigate($ie, $url, 0)
$file = FileOpen("c:\reverse_geocoding.txt")
msgbox(0,"",FileReadLine($file))
Func CreateHtml()
if FileExists(@TempDir&"\reverse_geocoding.html") then FileDelete(@TempDir&"\reverse_geocoding.html")
$sHTML = FileOpen(@TempDir&"\reverse_geocoding.html", 1)
FileWrite($sHTML,'<!DOCTYPE html>' &@CRLF& _
'<html>' &@CRLF& _
'<head>' &@CRLF& _
'<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>' &@CRLF& _
'<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>' &@CRLF& _
'<title>Google Maps JavaScript API v3 Example: Reverse Geocoding</title>' &@CRLF& _
'<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />' &@CRLF& _
'<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>' &@CRLF& _
'<script type="text/javascript">' &@CRLF& _
' var geocoder;' &@CRLF& _
' var map;' &@CRLF& _
' var infowindow = new google.maps.InfoWindow();' &@CRLF& _
' var marker; ' &@CRLF& _
' var sText;'&@CRLF&@CRLF& _
' function WriteToFile(sText) {' &@CRLF& _
' var fso = new ActiveXObject("Scripting.FileSystemObject");' &@CRLF& _
' var FileObject = fso.CreateTextFile("c:\\reverse_geocoding.txt",true)' &@CRLF& _
' FileObject.WriteLine(sText);' &@CRLF& _
' FileObject.close();' &@CRLF& _
' }'&@CRLF&@CRLF& _
' function initialize() {' &@CRLF& _
' geocoder = new google.maps.Geocoder();' &@CRLF& _
' var latlng = new google.maps.LatLng(40.730885,-73.997383);' &@CRLF& _
' var myOptions = {' &@CRLF& _
' zoom: 8,' &@CRLF& _
' center: latlng,' &@CRLF& _
" mapTypeId: 'roadmap'" &@CRLF& _
' }' &@CRLF& _
' map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);' &@CRLF& _
' codeLatLng();' &@CRLF& _
' }'&@CRLF&@CRLF& _
' function codeLatLng() {' &@CRLF& _
' var input = document.getElementById("latlng").value;' &@CRLF& _
' var latlngStr = input.split(",",2);' &@CRLF& _
' var lat = parseFloat(latlngStr[0]);' &@CRLF& _
' var lng = parseFloat(latlngStr[1]);' &@CRLF& _
' var latlng = new google.maps.LatLng(lat, lng);' &@CRLF& _
" geocoder.geocode({'latLng': latlng}, function(results, status) {" &@CRLF& _
' if (status == google.maps.GeocoderStatus.OK) {' &@CRLF& _
' if (results[1]) {' &@CRLF& _
' map.setZoom(11);' &@CRLF& _
' marker = new google.maps.Marker({' &@CRLF& _
' position: latlng,' &@CRLF& _
' map: map' &@CRLF& _
' });' &@CRLF& _
' infowindow.setContent(results[1].formatted_address);' &@CRLF& _
' infowindow.open(map, marker);' &@CRLF& _
' WriteToFile(results[1].formatted_address)' &@CRLF& _
' } else {' &@CRLF& _
' alert("No results found");' &@CRLF& _
' }' &@CRLF& _
' } else {' &@CRLF& _
' alert("Geocoder failed due to: " + status);' &@CRLF& _
' }' &@CRLF& _
' });' &@CRLF& _
' }' &@CRLF& _
'</script>' &@CRLF& _
'</head>' &@CRLF& _
'<body onload="initialize()">' &@CRLF& _
'<div>' &@CRLF& _
' <input id="latlng" type="textbox" value="LATITUDE,LONGITUDE">'&@CRLF&@CRLF& _
'</div>' &@CRLF& _
'<div>' &@CRLF& _
' <input type="button" value="Reverse Geocode" onclick="codeLatLng()">' &@CRLF& _
'</div>' &@CRLF& _
'<div id="map_canvas" style="height: 90%; top:60px; border: 1px solid black;"></div>' &@CRLF& _
'</body>' &@CRLF& _
'</html>')
FileClose($sHTML)
EndFunc
► Afficher le texte
Code : Tout sélectionner
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=GpsToAdress.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <IE.au3>
$FirstRun = False
$url = @TempDir & "\reverse_geocoding.html"
_IEErrorHandlerRegister()
$ie = _IECreateEmbedded()
$lat = 40.730885
$lon = -73.997383
$ZoomLevel = 8
CreateHtml()
GUICreate("GpsToAdress", 605,600, 0, 0,$WS_OVERLAPPEDWINDOW);, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_POPUPWINDOW, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
;GUICreate("GpsToAdress", 605,600, 0, 0, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX))
$adress_result = GUICtrlCreateInput("***",70,500,480,20,$ES_CENTER)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Coordonnées GPS :",110,530,150,20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$coordinates = GUICtrlCreateInput("40.730885,-73.997383",270,530,200,20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$adress_refresh = GUICtrlCreateButton("Refresh",500,530,80,20)
$ieobject = GUICtrlCreateObj($ie, 4, 5, 594, 492)
GUISetState(@SW_SHOW)
_IENavigate($ie, $url, 0)
$file = FileOpen(@TempDir&"\reverse_geocoding.txt")
GUICtrlSetData($adress_result,FileReadLine($file))
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then Exit
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $adress_refresh
$FirstRun = True
$val = StringSplit(GUICtrlRead($coordinates),",")
$lat = $val[1]
$lon = $val[2]
CreateHtml()
GUICtrlSetData($adress_result,FileReadLine($file))
EndSwitch
Wend
Func CreateHtml()
If $FirstRun = False Then $TextWritten = '"You are HERE !!!"'
If $FirstRun = True Then $TextWritten = "results[1].formatted_address"
if FileExists(@TempDir&"\reverse_geocoding.html") then FileDelete(@TempDir&"\reverse_geocoding.html")
$sHTML = FileOpen(@TempDir&"\reverse_geocoding.html", 1)
FileWrite($sHTML,'<!DOCTYPE html>' &@CRLF& _
'<html>' &@CRLF& _
'<head>' &@CRLF& _
'<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>' &@CRLF& _
'<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>' &@CRLF& _
'<title>Google Maps JavaScript API v3 Example: Reverse Geocoding</title>' &@CRLF& _
'<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />' &@CRLF& _
'<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>' &@CRLF& _
'<script type="text/javascript">' &@CRLF& _
' var geocoder;' &@CRLF& _
' var map;' &@CRLF& _
' var infowindow = new google.maps.InfoWindow();' &@CRLF& _
' var marker; ' &@CRLF& _
' var sText;'&@CRLF&@CRLF& _
' function WriteToFile(sText) {' &@CRLF& _
' var fso = new ActiveXObject("Scripting.FileSystemObject");' &@CRLF& _
' var path = fso.GetParentFolderName(unescape(self.location.pathname))' &@CRLF& _
' var fold = fso.GetFolder(path.substr(1))' &@CRLF& _
' var fich="reverse_geocoding.txt"' &@CRLF& _
' var FileObject = fso.CreateTextFile(fold+"/"+fich , 2, true);' &@CRLF& _
' FileObject.WriteLine(sText);' &@CRLF& _
' FileObject.close();' &@CRLF& _
' }'&@CRLF&@CRLF& _
' function initialize() {' &@CRLF& _
' geocoder = new google.maps.Geocoder();' &@CRLF& _
' var latlng = new google.maps.LatLng(40.730885,-73.997383);' &@CRLF& _
' var myOptions = {' &@CRLF& _
' zoom: '&$ZoomLevel&',' &@CRLF& _
' center: latlng,' &@CRLF& _
" mapTypeId: 'roadmap'" &@CRLF& _
' }' &@CRLF& _
' map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);' &@CRLF& _
' codeLatLng();' &@CRLF& _
' }'&@CRLF&@CRLF& _
' function codeLatLng() {' &@CRLF& _
' var input = document.getElementById("latlng").value;' &@CRLF& _
' var latlngStr = input.split(",",2);' &@CRLF& _
' var lat = parseFloat(latlngStr[0]);' &@CRLF& _
' var lng = parseFloat(latlngStr[1]);' &@CRLF& _
' var latlng = new google.maps.LatLng(lat, lng);' &@CRLF& _
" geocoder.geocode({'latLng': latlng}, function(results, status) {" &@CRLF& _
' if (status == google.maps.GeocoderStatus.OK) {' &@CRLF& _
' if (results[1]) {' &@CRLF& _
' map.setZoom(11);' &@CRLF& _
' marker = new google.maps.Marker({' &@CRLF& _
' position: latlng,' &@CRLF& _
' map: map' &@CRLF& _
' });' &@CRLF& _
' infowindow.setContent('&$TextWritten&');' &@CRLF& _
' infowindow.open(map, marker);' &@CRLF& _
' WriteToFile('&$TextWritten&')' &@CRLF& _
' } else {' &@CRLF& _
' alert("No results found");' &@CRLF& _
' }' &@CRLF& _
' } else {' &@CRLF& _
' alert("Geocoder failed due to: " + status);' &@CRLF& _
' }' &@CRLF& _
' });' &@CRLF& _
' }' &@CRLF& _
'</script>' &@CRLF& _
'</head>' &@CRLF& _
'<body onload="initialize()">' &@CRLF& _
'<div>' &@CRLF& _
' <input id="latlng" type="textbox" value="'&$lat&','&$lon&'">'&@CRLF&@CRLF& _
'</div>' &@CRLF& _
'<div id="map_canvas" style="width: 755px; height: 490px; border:1px solid black"></div>' &@CRLF& _
'</body>' &@CRLF& _
'</html>')
FileClose($sHTML)
EndFuncMerci par avance


