Jump to content
Sign in to follow this  
golfinhu

Google Earth New Address

Recommended Posts

golfinhu

Hi All, good? i have one file with 500 coordinates to plot in google earth...

I can create a google earth object using a code found here in the forum, but can not move to a new address, I searched the google earth api, but I can not work at all, does anyone have any idea how do that? thank you again

 

#include-once
#include <GUIConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <IE.au3>

Dim $msg, $ge
Global $main_gui



; Setup Main GUI
$main_gui = GUICreate("Google Earth Example", 800, 600, -1, -1, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX))
$ge_ctrl = _GUICtrlGoogleEarth_Create($ge, "AIzaSyAEna-zqz5hUjbiuzAXXRoWtR04MN1hzaU", 0, 10, 800, 450, "Palm Beach, Queensland, Australia", 1000, 2)
GUICtrlSetResizing($ge_ctrl, $GUI_DOCKTOP)
$close_button = GUICtrlCreateButton("Close (Esc)", 650, 515, 80, 20)
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER)

dim $main_gui_accel[1][2]=[["{ESC}", $close_button]]

; Show Main GUI
GUISetState(@SW_SHOW)
GUISetAccelerators($main_gui_accel)

; Main Loop
while 1

    If $msg = $GUI_EVENT_CLOSE or $msg = $close_button Then

        ExitLoop
    EndIf

    $msg = GUIGetMsg()
WEnd

GUIDelete()

func _GUICtrlGoogleMap_GetLatLng($address)
    Local $latlng[2]
    $address_part = StringSplit($address, ",", 2)
    ; if the geocode is a lat long
    if UBound($address_part) = 2 and IsNumber($address_part[0]) and IsNumber($address_part[1]) Then
        $latlng[0] = StringStripWS($address_part[0], 3)
        $latlng[1] = StringStripWS($address_part[1], 3)
    Else
        $s_Response = BinaryToString(InetRead("http://maps.googleapis.com/maps/api/geocode/json?address=" & _URIEncode($address), 1))
        $latlng = StringRegExp($s_Response, '(?s)"location" .+?"lat"\s*:\s*(-?\d+\.\d+).+? "lng"\s*:\s*(-?\d+\.\d+)', 3)
    EndIf
    Return $latlng
EndFunc

Func _URIEncode($sData)
    Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "")
    Local $nChar
    $sData = ""
    For $i = 1 To $aData[0]
        $nChar = Asc($aData[$i])
        Switch $nChar
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $sData &= $aData[$i]
            Case 32
                $sData &= "+"
            Case Else
                $sData &= "%" & Hex($nChar, 2)
        EndSwitch
    Next
    Return $sData
EndFunc   ;==>_URIEncode

; #FUNCTION# ;===============================================================================
;
; Name...........:  _GUICtrlGoogleEarth_Create()
; Description ...:  Creates a Google Map control.
; Syntax.........:  _GUICtrlGoogleEarth_Create(ByRef $ge, $gmap_api_key, $left, $top, $width, $height, $address, $zoom = 10000, $fly_to_speed = "ge.SPEED_TELEPORT")
; Parameters ....:  $ge             - The embedded Google Earth object, required by the _GUICtrlGoogleEarth functions below.
;                   $gmap_api_key   - A valid Google Maps API key (see Remarks below).
;                   $left           - The left side of the control.
;                   $top            - The top of the control.
;                   $width          - The width of the control.
;                   $height         - The height of the control.
;                   $address        - An address (either a location or latitude and longitude) to center the map on
;                                     ie. both "Sydney, New South Wales, Australia" and "-34.397, 150.644" are valid.
;                   $zoom           - An initial map zoom level (in meters).
;                   $fly_to_speed   - The speed to move to the above address.
;                                     The range is 0.0 to 5.0.
;                                     Using "ge.SPEED_TELEPORT" will move instantly.
; Return values .:  On Success      - Returns the identifier (controlID) of the new control.
;                   On Failure      - Returns False.
; Author ........:  seangriffin
; Modified.......:
; Remarks .......:  The Google Earth Plug-in must be installed in your Internet Explorer browser
;                   prior to using this function.  To install the plugin, using
;                   Internet Explorer visit "http://code.google.com/apis/earth" and follow
;                   the instructions provided.
;
;                   A Google Maps API key is also required for this function to work.
;                   You must obtain your own personal key from Google, and pass it into this
;                   function for it to work.  To obtain a key, visit
;                   "http://code.google.com/apis/maps/signup.html", and when prompted for
;                   your web site URL, supply the URL of "http://localhost".  You will
;                   also be asked to sign in with your Google Account details.
; Related .......:
; Link ..........:
; Example .......:  Yes
;
; ;==========================================================================================
func _GUICtrlGoogleEarth_Create(ByRef $ge, $gmap_api_key, $left, $top, $width, $height, $address, $zoom = 10000, $fly_to_speed = "ge.SPEED_TELEPORT")

    Local $latlng[2]

    $latlng = _GUICtrlGoogleMap_GetLatLng($address)

    Local Const $html = _
        "<html>" & @CRLF & _
        "<head>" & @CRLF & _
        "   <title>Sample</title>" & @CRLF & _
        "   <script src=""http://www.google.com/jsapi?key=" & $gmap_api_key & """> </script>" & @CRLF & _
        "   <script type=""text/javascript"">" & @CRLF & _
        "      var ge;" & @CRLF & _
        "      google.load(""earth"", ""1"");" & @CRLF & _
        "      function init() {" & @CRLF & _
        "         google.earth.createInstance('map3d', initCB, failureCB);" & @CRLF & _
        "      }" & @CRLF & _
        "      function initCB(instance) {" & @CRLF & _
        "         ge = instance;" & @CRLF & _
        "         ge.getWindow().setVisibility(true);" & @CRLF & _
        "         ge.getOptions().setFlyToSpeed(" & $fly_to_speed & ");" & @CRLF & _
        "         var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);" & @CRLF & _
        "         lookAt.setLatitude(" & $latlng[0] & ");" & @CRLF & _
        "         lookAt.setLongitude(" & $latlng[1] & ");" & @CRLF & _
        "         lookAt.setRange(" & $zoom & ");" & @CRLF & _
        "         ge.getView().setAbstractView(lookAt);" & @CRLF & _
        "      }" & @CRLF & _
        "      function failureCB(errorCode) {" & @CRLF & _
        "      }" & @CRLF & _
        "      google.setOnLoadCallback(init);" & @CRLF & _
        "   </script>" & @CRLF & _
        "</head>" & @CRLF & _
        "<body style=""margin:0px; padding:0px;"">" & @CRLF & _
        "   <div id=""map3d"" style=""width:100%; height:100%""></div>" & @CRLF & _
        "</body>" & @CRLF & _
        "</html>"

    $ge = _IECreateEmbedded ()
    $ge_ctrl = GUICtrlCreateObj($ge, $left, $top, $width, $height)
    _IENavigate($ge, "about:blank")
    _IEDocWriteHTML($ge, $html)
    $ge.refresh()
    _IELoadWait($ge)
    $ge.document.body.scroll = "no"
    Return $ge_ctrl
EndFunc

 

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • IMRafferty
      By IMRafferty
      Hi, I posted this to StackOverflow already (see below) and they said to 'AutoIt' it (see bottom) and gave me two down-votes. Can anybody help me get started?  I'm happy to paypal my gratitude in advance.  I'm brand new to AutoIt .  Have been watching tutorial videos on Youtube, but still climbing learning curve to get any initial momentum going.  Thank you for at least reading -Ian :
      Batch searching/verifying Mailing/Resident Addresses using Google - possible?
      Good tidings, St'overflow-ers!
      So I have the unenviable task of verifying keyed/transcribed hand-written mailing addresses from paper fishing licenses. We use Smartsoft/Frameworks as it catches/verifies about 90% (domestic, some Canada) of what we get from licensing, but for the 'leftovers', it's then time for the one-by-one Googling-steps below this 'graph with pics, rinse/repeat times 20,000+. Question: can I somehow batch/automate this (by feeding Google Maps/Places a google sheet or *.csv maybe?) to save time, or nope? or perhaps you fell asleep reading this q? Beuller? Thanks! -Ian
      (1) Copy 'rough' address from MS Excel (or Google Sheet): 


      (2) Paste & search in Google (usually goes right into searching Google_Places/Earth):
      (3) (Hopefully) get a 'hit' and copy more correct/'verified' address:

      (4) Make corrections/tweaks back in Excel/GoogleSheet (faster than copy/pasting):

      5) rinse/repeat times 20k (why I'm asking for help)
      Stackoverflow comments:
      "I think you should look into something like AutoIt instead of batch for something to do that complicated stuff. I use AutoIt for some works tasks that are the same over and over again. And since batch is so limited i dont think batch would be worth using here, but if you insist on using a build in program then i'd think VBS would work to an extend." – NizonRox 
      "You'd have to interact with EXCEL and a Browser. Batch can't do that. Autoit supports both". – Stephan
       
       
×