Jump to content

[SOLVED] _IECreateEmbedded Compiled won't run


 Share

Recommended Posts

1. The script in ie works without errors, why in Autoit does not work?

2. My goal: I would like to read the contents of the "

map.panTo(posizione);

" variable from the map and save it to a variable in autoit to use it.

THX.

PS: you need gmaps API key to execute it locally.

 

#include-once
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <IE.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 801, 601, 192, 124)
GUISetState(@SW_SHOW)
map()
#EndRegion ### END Koda GUI section ###

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

    EndSwitch
WEnd

Func map()
$apikey = "Insert your api key"
$html = _
"<!DOCTYPE html>" & @CRLF & _
"<html>" & @CRLF & _
"  <head>" & @CRLF & _
"    <meta charset=""utf-8"">" & @CRLF & _
"    <title>Searchbox</title>" & @CRLF & _
"    <style>" & @CRLF & _
"      #map {" & @CRLF & _
"        height: 100%;" & @CRLF & _
"      }" & @CRLF & _
"      html, body {" & @CRLF & _
"        height: 100%;" & @CRLF & _
"        margin: 0;" & @CRLF & _
"        padding: 0;" & @CRLF & _
"      }" & @CRLF & _
"      #map {  " & @CRLF & _
"        height: 99%;  " & @CRLF & _
"        width: 99%;" & @CRLF & _
"      }  " & @CRLF & _
"     #pac-input{" & @CRLF & _
"       margin: 10 10 10 10;" & @CRLF & _
"       width: 200px;" & @CRLF & _
"       position: absolute; top: 10px; left: 400px; z-index: 99;" & @CRLF & _
"     }" & @CRLF & _
"    </style>" & @CRLF & _
"  </head>" & @CRLF & _
"  <body>" & @CRLF & _
"    <div id=""map""></div>" & @CRLF & _
"    <script>" & @CRLF & _
"" & @CRLF & _
"      function initAutocomplete() {" & @CRLF & _
"       var myLatLng = {lat: 41.8956142, lng: 12.5029109};                                             " & @CRLF & _
"        var map = new google.maps.Map(document.getElementById('map'), {" & @CRLF & _
"          center: myLatLng," & @CRLF & _
"         zoom:15," & @CRLF & _
"          mapTypeId: 'roadmap'" & @CRLF & _
"        });" & @CRLF & _
"       " & @CRLF & _
"       " & @CRLF & _
"       var markers = [];" & @CRLF & _
"       " & @CRLF & _
"       map.addListener('click', function(e) {" & @CRLF & _
"       placeMarker(e.latLng, map);     " & @CRLF & _
"       " & @CRLF & _
"       });" & @CRLF & _
"                       " & @CRLF & _
"       function placeMarker(position, map) {" & @CRLF & _
"       " & @CRLF & _
"           var marker = new google.maps.Marker({" & @CRLF & _
"               position: position," & @CRLF & _
"               map: map                " & @CRLF & _
"           }); " & @CRLF & _
"           var lastpos = position;" & @CRLF & _
"           markers.push(marker);" & @CRLF & _
"           for (var i = 0; i < markers.length; i++) {" & @CRLF & _
"               if (markers[i].getPosition() != lastpos) {                 " & @CRLF & _
"                   markers[i].setMap(null);" & @CRLF & _
"                   markers.splice(i, 1)" & @CRLF & _
"               }" & @CRLF & _
"            }" & @CRLF & _
"           mapMove(lastpos);" & @CRLF & _
"       }" & @CRLF & _
"" & @CRLF & _
"       function mapMove(posizione){" & @CRLF & _
"           map.panTo(posizione);" & @CRLF & _
"           alert(posizione);" & @CRLF & _
"       }" & @CRLF & _
"" & @CRLF & _
"       " & @CRLF & _
"     }" & @CRLF & _
"" & @CRLF & _
"    </script>" & @CRLF & _
"    <script src=""https://maps.googleapis.com/maps/api/js?key="&$apikey&"&libraries=places&callback=initAutocomplete""" & @CRLF & _
"         async defer></script>" & @CRLF & _
"  </body>" & @CRLF & _
"</html>"


    $gmap = _IECreateEmbedded()
    $gmap_ctrl = GUICtrlCreateObj($gmap, 5, 5, 750, 550)
    _IENavigate($gmap, "about:blank", 0)
    _IEDocWriteHTML($gmap, $html)

EndFunc
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Searchbox</title>
    <style>
      #map {
        height: 100%;
      }
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {  
        height: 99%;  
        width: 99%;
      }  
      #pac-input{
        margin: 10 10 10 10;
        width: 200px;
        position: absolute; top: 10px; left: 400px; z-index: 99;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>

      function initAutocomplete() {
        var myLatLng = {lat: 41.8956142, lng: 12.5029109};                                             
        var map = new google.maps.Map(document.getElementById('map'), {
          center: myLatLng,
          zoom:15,
          mapTypeId: 'roadmap'
        });
        
        
        var markers = [];
        
        map.addListener('click', function(e) {
        placeMarker(e.latLng, map);     
        
        });
                        
        function placeMarker(position, map) {
        
            var marker = new google.maps.Marker({
                position: position,
                map: map                
            }); 
            var lastpos = position;
            markers.push(marker);
            for (var i = 0; i < markers.length; i++) {
                if (markers[i].getPosition() != lastpos) {                 
                    markers[i].setMap(null);
                    markers.splice(i, 1)
                }
            }
            mapMove(lastpos);
        }

        function mapMove(posizione){
            map.panTo(posizione);
            alert(posizione);
        }

        
      }

    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=yourapikey&libraries=places&callback=initAutocomplete"
         async defer></script>
  </body>
</html>

 

Edited by rootx
Link to comment
Share on other sites

OK, I have fixed the click function... But why this setting does't work??? map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

Inside IE 11 it work fine, the input box looks in the center.

Please explain me why, thx.

#include-once
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <IE.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 801, 601, 192, 124)
GUISetState(@SW_SHOW)
map()
#EndRegion ### END Koda GUI section ###

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

    EndSwitch
WEnd

Func map()
$apikey = "AIzaSyBPQwec2vusz4JGzcBL__mJL2t1ZeIOYOA"
$html = _
"<!DOCTYPE html>" & @CRLF & _
"<html>" & @CRLF & _
"  <head> <!-- www.techstrikers.com -->" & @CRLF & _
"    <meta name=""viewport"" content=""initial-scale=1.0, user-scalable=no"">" & @CRLF & _
"    <meta charset=""utf-8"">" & @CRLF & _
"    <title>On Click Draw Markers</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 & _
"      #description {" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 15px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #infowindow-content .title {" & @CRLF & _
"        font-weight: bold;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #infowindow-content {" & @CRLF & _
"        display: none;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #map #infowindow-content {" & @CRLF & _
"        display: inline;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-card {" & @CRLF & _
"        margin: 10px 10px 0 0;" & @CRLF & _
"        border-radius: 2px 0 0 2px;" & @CRLF & _
"        box-sizing: border-box;" & @CRLF & _
"        -moz-box-sizing: border-box;" & @CRLF & _
"        outline: none;" & @CRLF & _
"        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);" & @CRLF & _
"        background-color: #fff;" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-container {" & @CRLF & _
"        padding-bottom: 12px;" & @CRLF & _
"        margin-right: 12px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-controls {" & @CRLF & _
"        display: inline-block;" & @CRLF & _
"        padding: 5px 11px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-controls label {" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 13px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-input {" & @CRLF & _
"        background-color: #fff;" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 15px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"        margin-left: 12px;" & @CRLF & _
"        padding: 0 11px 0 13px;" & @CRLF & _
"        text-overflow: ellipsis;" & @CRLF & _
"        width: 400px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-input:focus {" & @CRLF & _
"        border-color: #4d90fe;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #title {" & @CRLF & _
"        color: #fff;" & @CRLF & _
"        background-color: #4d90fe;" & @CRLF & _
"        font-size: 25px;" & @CRLF & _
"        font-weight: 500;" & @CRLF & _
"        padding: 6px 12px;" & @CRLF & _
"      }" & @CRLF & _
"      #target {" & @CRLF & _
"        width: 345px;" & @CRLF & _
"      }" & @CRLF & _
"    </style>" & @CRLF & _
"" & @CRLF & _
"<script src=""https://maps.googleapis.com/maps/api/js?key="&$apikey&"&libraries=places&callback=initMap"" async defer></script>" & @CRLF & _
"<script>" & @CRLF & _
"var map;" & @CRLF & _
"function initMap() {" & @CRLF & _
"  var lat_lng = {lat: 17.08672, lng: 78.42444};" & @CRLF & _
"  map = new google.maps.Map(document.getElementById('map'), {" & @CRLF & _
"    zoom: 7," & @CRLF & _
"    center: lat_lng," & @CRLF & _
"    mapTypeId: google.maps.MapTypeId.TERRAIN" & @CRLF & _
"  });" & @CRLF & _
"  // This event listener will call addMarker() when the map is clicked." & @CRLF & _
"  map.addListener('click', function(event) {" & @CRLF & _
"    addMarker(event.latLng);" & @CRLF & _
"  });" & @CRLF & _
"         //search autocomplete" & @CRLF & _
"         var input = document.getElementById('pac-input');" & @CRLF & _
"         var autocomplete = new google.maps.places.Autocomplete(input);" & @CRLF & _
"         map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);" & @CRLF & _
"         autocomplete.addListener('place_changed', function() {" & @CRLF & _
"           var XlatLng = new google.maps.LatLng(autocomplete.getPlace().geometry.location.lat(), autocomplete.getPlace().geometry.location.lng());" & @CRLF & _
"           addMarker(XlatLng)" & @CRLF & _
"         });" & @CRLF & _
"}" & @CRLF & _
"var markers = [];" & @CRLF & _
"// Adds a marker to the map and push to the array." & @CRLF & _
"function addMarker(location) {" & @CRLF & _
"  var marker = new google.maps.Marker({" & @CRLF & _
"    position: location," & @CRLF & _
"    map: map" & @CRLF & _
"  });" & @CRLF & _
"  markers.push(marker);" & @CRLF & _
"   for (var i = 0; i < markers.length; i++) {" & @CRLF & _
"               if (markers[i].getPosition() != location) {" & @CRLF & _
"                   markers[i].setMap(null);" & @CRLF & _
"                   //Remove the marker from array." & @CRLF & _
"                   markers.splice(i, 1)" & @CRLF & _
"               }" & @CRLF & _
"            }" & @CRLF & _
"   map.panTo(location);" & @CRLF & _
"   alert(location);" & @CRLF & _
"}" & @CRLF & _
" </script>" & @CRLF & _
"  </head>" & @CRLF & _
"  <body>" & @CRLF & _
"  <input id=""pac-input"" class=""controls"" type=""text"" placeholder=""Search Box"">" & @CRLF & _
"    <div id=""map""></div>" & @CRLF & _
"  </body>" & @CRLF & _
"</html>"
    $gmap = _IECreateEmbedded()
    $gmap_ctrl = GUICtrlCreateObj($gmap, 5, 5, 750, 550)
    _IENavigate($gmap, "about:blank", 0)
    _IEDocWriteHTML($gmap, $html)
EndFunc

 

Link to comment
Share on other sites

Hi @rootx, from a quick test it seems that the HTML listing here works in the same way if is opened in the IE browser as in the embedded browser control in the GUI as well.
What exactly doesn't works for you?
Here the inputbox is located on the "TOP_LEFT" of the browser both in the IE browser and in the GUI on the embedded browser control as well.

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

try to remove this line of your listing:

"  <head> <!-- www.techstrikers.com -->" & @CRLF & _

and change it with this 2 lines:

"  <head>" & @CRLF & _
"  <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _

... Let us know the results ...

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

THX THX THX Chimp! The fix works well

I implemented this example found on techstrikers, with my script, to get a single function that will return latitude and longitude in both cases (click event or the imput box with autocomplete suggestion). Now I need a way to store in Autoit variable the result from my script (var location) , how can I do it?? THX

 

Edited by rootx
Link to comment
Share on other sites

3 hours ago, rootx said:

.... Now I need a way to store in Autoit variable the result from my script (var location) , how can I do it?? THX

To exchange data between autoit and javascript you need to set some settings in both environments. Take a look at the code lines marked with ; <--- to get an idea of the changes I've made. (p.s. Also have a look here for some further infos)

#include-once
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <IE.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 801, 601, 192, 124)
GUISetState(@SW_SHOW)
Global $gmap, $oLat_Long ; <--- global variables (reference to the browser control and the location)

map()

Global $ohJS = $gmap.document.parentwindow.JSglobal ; <--- create a reference to javascript (JSglobal must be previously created in the html page)

#EndRegion ### END Koda GUI section ###

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

    EndSwitch
    If $ohJS.lat_long <> $oLat_Long Then ; <--- check if location has changed
        $oLat_Long =  $ohJS.lat_long ; <--- get reference to the coordinates object
        MsgBox(0,"AutoIt", "Following variables comes from javascript" & @CRLF & "and are read from within AutoIt" & @CRLF &  @CRLF & "Location is:" & @CRLF & "Latitude: " & $ohJS.lat_long.lat() & @CRLF & "Longitude: " & $ohJS.lat_long.lng() ) ; <-- get coordinates
    EndIf

WEnd

Func map()
$apikey = "AIzaSyBPQwec2vusz4JGzcBL__mJL2t1ZeIOYOA"
$html = _
"<!DOCTYPE html>" & @CRLF & _
"<html>" & @CRLF & _
"  <head>" & @CRLF & _
"  <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _ ; <--- set up the browser control mode
            "   <script type=""text/javascript"">" & @CRLF & _ ; <--- create some global variables
            "       var JSglobal = (1,eval)(""this"");" & @CRLF & _ ; <--- this will be referenced from AutoIt
            "       var lat_long;" & @CRLF & _ ; <--- temporary storage for coordinates
            "   </script>" & @CRLF & _
"    <meta name=""viewport"" content=""initial-scale=1.0, user-scalable=no"">" & @CRLF & _
"    <meta charset=""utf-8"">" & @CRLF & _
"    <title>On Click Draw Markers</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 & _
"      #description {" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 15px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #infowindow-content .title {" & @CRLF & _
"        font-weight: bold;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #infowindow-content {" & @CRLF & _
"        display: none;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #map #infowindow-content {" & @CRLF & _
"        display: inline;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-card {" & @CRLF & _
"        margin: 10px 10px 0 0;" & @CRLF & _
"        border-radius: 2px 0 0 2px;" & @CRLF & _
"        box-sizing: border-box;" & @CRLF & _
"        -moz-box-sizing: border-box;" & @CRLF & _
"        outline: none;" & @CRLF & _
"        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);" & @CRLF & _
"        background-color: #fff;" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-container {" & @CRLF & _
"        padding-bottom: 12px;" & @CRLF & _
"        margin-right: 12px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-controls {" & @CRLF & _
"        display: inline-block;" & @CRLF & _
"        padding: 5px 11px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-controls label {" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 13px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-input {" & @CRLF & _
"        background-color: #fff;" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 15px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"        margin-left: 12px;" & @CRLF & _
"        padding: 0 11px 0 13px;" & @CRLF & _
"        text-overflow: ellipsis;" & @CRLF & _
"        width: 400px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-input:focus {" & @CRLF & _
"        border-color: #4d90fe;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #title {" & @CRLF & _
"        color: #fff;" & @CRLF & _
"        background-color: #4d90fe;" & @CRLF & _
"        font-size: 25px;" & @CRLF & _
"        font-weight: 500;" & @CRLF & _
"        padding: 6px 12px;" & @CRLF & _
"      }" & @CRLF & _
"      #target {" & @CRLF & _
"        width: 345px;" & @CRLF & _
"      }" & @CRLF & _
"    </style>" & @CRLF & _
"" & @CRLF & _
"<script src=""https://maps.googleapis.com/maps/api/js?key="&$apikey&"&libraries=places&callback=initMap"" async defer></script>" & @CRLF & _
"<script>" & @CRLF & _
"var map;" & @CRLF & _
"function initMap() {" & @CRLF & _
"  var lat_lng = {lat: 43.88967769200741, lng: 8.039529919624328};" & @CRLF & _
"  map = new google.maps.Map(document.getElementById('map'), {" & @CRLF & _
"    zoom: 15," & @CRLF & _
"    center: lat_lng," & @CRLF & _
"    mapTypeId: google.maps.MapTypeId.TERRAIN" & @CRLF & _
"  });" & @CRLF & _
"  // This event listener will call addMarker() when the map is clicked." & @CRLF & _
"  map.addListener('click', function(event) {" & @CRLF & _
"    addMarker(event.latLng);" & @CRLF & _
"  });" & @CRLF & _
"         //search autocomplete" & @CRLF & _
"         var input = document.getElementById('pac-input');" & @CRLF & _
"         var autocomplete = new google.maps.places.Autocomplete(input);" & @CRLF & _
"         map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);" & @CRLF & _
"         autocomplete.addListener('place_changed', function() {" & @CRLF & _
"           var XlatLng = new google.maps.LatLng(autocomplete.getPlace().geometry.location.lat(), autocomplete.getPlace().geometry.location.lng());" & @CRLF & _
"           addMarker(XlatLng)" & @CRLF & _
"         });" & @CRLF & _
"}" & @CRLF & _
"var markers = [];" & @CRLF & _
"// Adds a marker to the map and push to the array." & @CRLF & _
"function addMarker(location) {" & @CRLF & _
"  var marker = new google.maps.Marker({" & @CRLF & _
"    position: location," & @CRLF & _
"    map: map" & @CRLF & _
"  });" & @CRLF & _
"  markers.push(marker);" & @CRLF & _
"   for (var i = 0; i < markers.length; i++) {" & @CRLF & _
"               if (markers[i].getPosition() != location) {" & @CRLF & _
"                   markers[i].setMap(null);" & @CRLF & _
"                   //Remove the marker from array." & @CRLF & _
"                   markers.splice(i, 1)" & @CRLF & _
"               }" & @CRLF & _
"            }" & @CRLF & _
"   map.panTo(location);" & @CRLF & _
"   lat_long = location;" & @CRLF & _ ; <--- store 'location' to a temp variable (it will be read from AutoIt)
"   alert('Hello from Javascript' + String.fromCharCode(13) + String.fromCharCode(13) + lat_long);" & @CRLF & _
"}" & @CRLF & _
" </script>" & @CRLF & _
"  </head>" & @CRLF & _
"  <body>" & @CRLF & _
"  <input id=""pac-input"" class=""controls"" type=""text"" placeholder=""Search Box"">" & @CRLF & _
"    <div id=""map""></div>" & @CRLF & _
"  </body>" & @CRLF & _
"</html>"
    $gmap = _IECreateEmbedded()
    $gmap_ctrl = GUICtrlCreateObj($gmap, 5, 5, 750, 550)
    _IENavigate($gmap, "about:blank", 0)
    _IEDocWriteHTML($gmap, $html)
EndFunc

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 4 weeks later...

The script does not work anymore !!! The gmaps key works in the browser, but in Autoit I have a white screen ... I did not do anything, what could have happened? Windows 10 Home 64bit, IE 11.540.15063.0 Update KB4034733.

NEW KEY "AIzaSyBZo1hXkaS1VKoLRaDpH5oPG7cpY1OkKKY"

THX

Link to comment
Share on other sites

I tried this tricks without success...

;$iZone = 0 ; My Computer
$iZone = 1 ; Local Intranet Zone
;$iZone = 2 ; Trusted sites Zone
;$iZone = 3 ; Internet Zone
;$izone = 4 ; Restricted Sites Zone

RegWrite("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\" & $iZone, "1208", "REG_DWORD", 0)

My suspect is.... this message in IE before Run the gmaps map The web page was prevented from running scripts or activex controls , I'm not sure if it causes me a problem, How can I disable It??

Link to comment
Share on other sites

Take a look at this link : https://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version
And read this step: "Browser Version Reporting is incorrect"
in short, when a web server check the version of the browser that is running on the client, the browsercontrol report himself as IE7 even if is emulating a newer version. (search for "UserAgent')
This can generate problems if the server web refuse to work on older browsers.

A possible workaround is to set a registry key as explained always in the above link.
Setting the registry should report the version specified in the key instead of IE7, fooling the web server and making your app working.
try to set this key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
and set the keyname autoit3.exe to a value of 11000 and your script should work.

.... Let us know the results ....

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Thx, 4 explanation, So since 2 days Google has adopted this new policy!!!

I start to be bored by google, because it continues to deprecate functions etc ... and every time even following the standard, I find myself with scripts that do not work, and documentation is not as accurate as Microsoft.

THX again.

Link to comment
Share on other sites

  • 2 months later...
;Rootx Find gps coord from Autoit window
#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>
#include <WinAPI.au3>
#include <StringConstants.au3>

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION","autoit3.exe","REG_DWORD", 11000)

Global $key = "AIzaSyBZo1hXkaS1VKoLRaDpH5oPG7cpY1OkKKY"

$Gps2Img = GUICreate("Get GPS Coord", 800, 700, -1, -1)
GUISetBkColor(0x404040)
GUICtrlSetDefColor(0xEDEDED)
GUICtrlSetDefBkColor(0x000000)

$LLat = GUICtrlCreateLabel("Latitude", 10, 520, 200, 21)
GUICtrlSetBkColor(-1,0x404040)
$iLat = GUICtrlCreateInput("", 10, 542, 200, 21)
$LLon = GUICtrlCreateLabel("Longitude", 10, 572, 200, 21)
GUICtrlSetBkColor(-1,0x404040)
$iLong = GUICtrlCreateInput("", 10, 592, 200, 21)

GUISetState(@SW_SHOW)
Global $gmap, $oLat_Long ; <--- global variables (reference to the browser control and the location)
Local $online = Ping("www.google.com")
    If not @error Then
        map()
    Else
        ;_GUICtrlStatusBar_SetText($StatusBar, "Your Internet Connection Status is Offline", 0)
    EndIf

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 <> $oLat_Long Then ; <--- check if location has changed
        $oLat_Long =  $ohJS.lat_long ; <--- get reference to the coordinates object
        ;MsgBox(0,"AutoIt", "Latitude: " & $ohJS.lat_long.lat() & @CRLF & "Longitude: " & $ohJS.lat_long.lng() ) ; <-- get coordinates
        GUICtrlSetData($iLat,$ohJS.lat_long.lat())
        GUICtrlSetData($iLong,$ohJS.lat_long.lng())
    EndIf

WEnd

Func map()

$html = _
"<!DOCTYPE html>" & @CRLF & _
"<html>" & @CRLF & _
"  <head>" & @CRLF & _
"  <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />" & @CRLF & _ ; <--- set up the browser control mode
            "   <script type=""text/javascript"">" & @CRLF & _ ; <--- create some global variables
            "       var JSglobal = (1,eval)(""this"");" & @CRLF & _ ; <--- this will be referenced from AutoIt
            "       var lat_long;" & @CRLF & _ ; <--- temporary storage for coordinates
            "   </script>" & @CRLF & _
"    <meta name=""viewport"" content=""initial-scale=1.0, user-scalable=no"">" & @CRLF & _
"    <meta charset=""utf-8"">" & @CRLF & _
"    <title>On Click Draw Markers</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 & _
"      #description {" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 15px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #infowindow-content .title {" & @CRLF & _
"        font-weight: bold;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #infowindow-content {" & @CRLF & _
"        display: none;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #map #infowindow-content {" & @CRLF & _
"        display: inline;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-card {" & @CRLF & _
"        margin: 10px 10px 0 0;" & @CRLF & _
"        border-radius: 2px 0 0 2px;" & @CRLF & _
"        box-sizing: border-box;" & @CRLF & _
"        -moz-box-sizing: border-box;" & @CRLF & _
"        outline: none;" & @CRLF & _
"        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);" & @CRLF & _
"        background-color: #fff;" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-container {" & @CRLF & _
"        padding-bottom: 12px;" & @CRLF & _
"        margin-right: 12px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-controls {" & @CRLF & _
"        display: inline-block;" & @CRLF & _
"        padding: 5px 11px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      .pac-controls label {" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 13px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-input {" & @CRLF & _
"        background-color: #fff;" & @CRLF & _
"        font-family: Roboto;" & @CRLF & _
"        font-size: 15px;" & @CRLF & _
"        font-weight: 300;" & @CRLF & _
"        margin-left: 12px;" & @CRLF & _
"        padding: 0 11px 0 13px;" & @CRLF & _
"        text-overflow: ellipsis;" & @CRLF & _
"        width: 400px;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #pac-input:focus {" & @CRLF & _
"        border-color: #4d90fe;" & @CRLF & _
"      }" & @CRLF & _
"" & @CRLF & _
"      #title {" & @CRLF & _
"        color: #fff;" & @CRLF & _
"        background-color: #4d90fe;" & @CRLF & _
"        font-size: 25px;" & @CRLF & _
"        font-weight: 500;" & @CRLF & _
"        padding: 6px 12px;" & @CRLF & _
"      }" & @CRLF & _
"      #target {" & @CRLF & _
"        width: 345px;" & @CRLF & _
"      }" & @CRLF & _
"    </style>" & @CRLF & _
"" & @CRLF & _
"<script src=""https://maps.googleapis.com/maps/api/js?key="&$key&"&libraries=places&callback=initMap"" async defer></script>" & @CRLF & _
"<script>" & @CRLF & _
"var map;" & @CRLF & _
"function initMap() {" & @CRLF & _
"  var lat_lng = {lat: 41.8951173, lng: 12.50483840000004};" & @CRLF & _
"  map = new google.maps.Map(document.getElementById('map'), {" & @CRLF & _
"    zoom: 10," & @CRLF & _
"    center: lat_lng," & @CRLF & _
"    mapTypeId: google.maps.MapTypeId.TERRAIN" & @CRLF & _
"  });" & @CRLF & _
"  // This event listener will call addMarker() when the map is clicked." & @CRLF & _
"  map.addListener('click', function(event) {" & @CRLF & _
"    addMarker(event.latLng);" & @CRLF & _
"  });" & @CRLF & _;"google.maps.event.addListener(map,  'rightclick',  function(mouseEvent) { alert('ciao');});"& @CRLF & _
"         //search autocomplete" & @CRLF & _
"         var input = document.getElementById('pac-input');" & @CRLF & _
"         var autocomplete = new google.maps.places.Autocomplete(input);" & @CRLF & _
"         map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);" & @CRLF & _
"         autocomplete.addListener('place_changed', function() {" & @CRLF & _
"           var XlatLng = new google.maps.LatLng(autocomplete.getPlace().geometry.location.lat(), autocomplete.getPlace().geometry.location.lng());" & @CRLF & _
"           addMarker(XlatLng)" & @CRLF & _
"         });" & @CRLF & _
"}" & @CRLF & _
"var markers = [];" & @CRLF & _
"// Adds a marker to the map and push to the array." & @CRLF & _
"function addMarker(location) {" & @CRLF & _
"  var marker = new google.maps.Marker({" & @CRLF & _
"    position: location," & @CRLF & _
"    map: map" & @CRLF & _
"  });" & @CRLF & _
"  markers.push(marker);" & @CRLF & _
"   for (var i = 0; i < markers.length; i++) {" & @CRLF & _
"               if (markers[i].getPosition() != location) {" & @CRLF & _
"                   markers[i].setMap(null);" & @CRLF & _
"                   //Remove the marker from array." & @CRLF & _
"                   markers.splice(i, 1)" & @CRLF & _
"               }" & @CRLF & _
"            }" & @CRLF & _
"   map.panTo(location);" & @CRLF & _
"   lat_long = location;" & @CRLF & _ ; <--- store 'location' to a temp variable (it will be read from AutoIt)
"   //alert('Hello from Javascript' + String.fromCharCode(13) + String.fromCharCode(13) + lat_long);" & @CRLF & _
"}" & @CRLF & _
" </script>" & @CRLF & _
"  </head>" & @CRLF & _
"  <body>" & @CRLF & _
"  <input id=""pac-input"" class=""controls"" type=""text"" placeholder=""Search Box"">" & @CRLF & _
"    <div id=""map""></div>" & @CRLF & _
"  </body>" & @CRLF & _
"</html>"
    $gmap = _IECreateEmbedded()
    $gmap_ctrl = GUICtrlCreateObj($gmap, 5, 5, 790, 500)
    _IENavigate($gmap, "about:blank", 0)
    _IEDocWriteHTML($gmap, $html)
EndFunc

The script works perfectly in autoit, if I compile It I don't see the map, if I press F5 I see the map but Autoit crashes. But Before It worked! 

Win 10 64bit [Version 10.0.16299.19], IE 11.15.16299, AutoIt3Wrapper v.16.612.1119.0 SciTE v.3.6.6.0

THX

Edited by rootx
Link to comment
Share on other sites

when you compile a script the name of the executable is no more autoit3.exe, but it's "the name of your script" .exe,  so you have to adjust accordingly the name of the executable specified in the RegWrite statement from"autoit3.exe" to "yourscriptname.exe". This should fix your issue of the compiled script.
let us know the results of the fix...

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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

×
×
  • Create New...