Jump to content

[SOLVED] _IE Reverse Geocoding Help


rootx
 Share

Recommended Posts

HI, my goal is read the formatted address.  "               lat_long = location// results[0].formatted_address;" & @CRLF & _ ;<---------Read this adrr

Trouble: The button Reverse Geocode doesn't works, and I'm not sure why. Thx

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <ButtonConstants.au3>
#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <INet.au3>
#include <File.au3>
#include <EditConstants.au3>
#include <Date.au3>
#include <Math.au3>
#include <GuiStatusBar.au3>
#include <IE.au3>

Global $reversecord

$form1 = GUICreate("test", 800, 600, -1, -1)


GUISetState(@SW_SHOW)


Global $gmap,$reversecord
map()
Global $ohJS = $gmap.document.parentwindow.JSglobal ;<-- read inside window ie



While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch


    If $ohJS.lat_long <> $reversecord Then ; <--- check if location has changed
       $reversecord =  $ohJS.lat_long ; <--- get reference to the adrr
        ;MsgBox(0,"AutoIt", "Latitude: " & $ohJS.lat_long.lat() & @CRLF & "Longitude: " & $ohJS.lat_long.lng() ) ; <-- get coordinates
        MsgBox("","",$reversecord)
    EndIf


WEnd


Func map()

$html = _
"<!DOCTYPE html>" & @CRLF & _
"<html>" & @CRLF & _
"  <head>" & @CRLF & _
"   <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _
"   <script type=""text/javascript"">" & @CRLF & _
"       var JSglobal = (1,eval)(""this"");" & @CRLF & _ ; <--- this will be referenced from AutoIt
"       var lat_long;" & @CRLF & _  ; <--- temporary storage for adrr
"   </script>" & @CRLF & _
"    <meta name=""viewport"" content=""initial-scale=1.0, user-scalable=no"">" & @CRLF & _
"    <meta charset=""utf-8"">" & @CRLF & _
"    <title>Reverse Geocoding</title>" & @CRLF & _
"    <style>" & @CRLF & _
"      /* Always set the map height explicitly to define the size of the div" & @CRLF & _
"       * element that contains the map. */" & @CRLF & _
"      #map {" & @CRLF & _
"        height: 100%;" & @CRLF & _
"      }" & @CRLF & _
"      /* Optional: Makes the sample page fill the window. */" & @CRLF & _
"      html, body {" & @CRLF & _
"        height: 100%;" & @CRLF & _
"        margin: 0;" & @CRLF & _
"        padding: 0;" & @CRLF & _
"      }" & @CRLF & _
"      #floating-panel {" & @CRLF & _
"        position: absolute;" & @CRLF & _
"        top: 10px;" & @CRLF & _
"        left: 25%;" & @CRLF & _
"        z-index: 5;" & @CRLF & _
"        background-color: #fff;" & @CRLF & _
"        padding: 5px;" & @CRLF & _
"        border: 1px solid #999;" & @CRLF & _
"        text-align: center;" & @CRLF & _
"        font-family: 'Roboto','sans-serif';" & @CRLF & _
"        line-height: 30px;" & @CRLF & _
"        padding-left: 10px;" & @CRLF & _
"      }" & @CRLF & _
"      #floating-panel {" & @CRLF & _
"        position: absolute;" & @CRLF & _
"        top: 5px;" & @CRLF & _
"        left: 50%;" & @CRLF & _
"        margin-left: -180px;" & @CRLF & _
"        width: 350px;" & @CRLF & _
"        z-index: 5;" & @CRLF & _
"        background-color: #fff;" & @CRLF & _
"        padding: 5px;" & @CRLF & _
"        border: 1px solid #999;" & @CRLF & _
"      }" & @CRLF & _
"      #latlng {" & @CRLF & _
"        width: 225px;" & @CRLF & _
"      }" & @CRLF & _
"    </style>" & @CRLF & _
"  </head>" & @CRLF & _
"  <body>" & @CRLF & _
"    <div id=""floating-panel"">" & @CRLF & _
"      <input id=""latlng"" type=""text"" value=""40.714224,-73.961452"">" & @CRLF & _
"      <input id=""submit"" type=""button"" value=""Reverse Geocode"">" & @CRLF & _
"    </div>" & @CRLF & _
"    <div id=""map""></div>" & @CRLF & _
"    <script>" & @CRLF & _
"      function initMap() {" & @CRLF & _
"        var map = new google.maps.Map(document.getElementById('map'), {" & @CRLF & _
"          zoom: 8," & @CRLF & _
"          center: {lat: 40.731, lng: -73.997}" & @CRLF & _
"        });" & @CRLF & _
"        var geocoder = new google.maps.Geocoder;" & @CRLF & _
"        var infowindow = new google.maps.InfoWindow;" & @CRLF & _
"" & @CRLF & _
"        document.getElementById('submit').addEventListener('click', function() {" & @CRLF & _
"          geocodeLatLng(geocoder, map, infowindow);" & @CRLF & _
"        });" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      function geocodeLatLng(geocoder, map, infowindow) {" & @CRLF & _
"        var input = document.getElementById('latlng').value;" & @CRLF & _
"        var latlngStr = input.split("&"'"&","&"'"&", 2);" & @CRLF & _
"        var latlng = {lat: parseFloat(latlngStr[0]), lng: parseFloat(latlngStr[1])};" & @CRLF & _
"        geocoder.geocode({'location': latlng}, function(results, status) {" & @CRLF & _
"          if (status === 'OK') {" & @CRLF & _
"            if (results[0]) {" & @CRLF & _
"              map.setZoom(11);" & @CRLF & _
"              var marker = new google.maps.Marker({" & @CRLF & _
"                position: latlng," & @CRLF & _
"                map: map" & @CRLF & _
"              });" & @CRLF & _
"              infowindow.setContent(results[0].formatted_address);" & @CRLF & _
"              infowindow.open(map, marker);" & @CRLF & _
"              lat_long = results[0].formatted_address;" & @CRLF & _ ;<---------Read this adrr
"              alert(lat_long);" & @CRLF & _
"            } else {" & @CRLF & _
"              window.alert('No results found');" & @CRLF & _
"            }" & @CRLF & _
"          } else {" & @CRLF & _
"            window.alert('Geocoder failed due to: ' + status);" & @CRLF & _
"          }" & @CRLF & _
"        });" & @CRLF & _
"      }" & @CRLF & _
"    </script>" & @CRLF & _
"    <script async defer" & @CRLF & _
"    src=""https://maps.googleapis.com/maps/api/js?key=AIzaSyBZo1hXkaS1VKoLRaDpH5oPG7cpY1OkKKY&callback=initMap"">" & @CRLF & _
"    </script>" & @CRLF & _
"  </body>" & @CRLF & _
"</html>"
    $gmap = _IECreateEmbedded()
    $gmap_ctrl = GUICtrlCreateObj($gmap, 5, 5, 790, 590)
    _IENavigate($gmap, "about:blank", 0)
    _IEDocWriteHTML($gmap, $html)
EndFunc

 

Edited by rootx
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...