Werty Posted June 8, 2010 Share Posted June 8, 2010 (edited) A small example using the Google Earth COM API (http://earth.google.com/comapi/index.html) Shows Longitude, Latitude and Altitude from the center of the GE render window. #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Google Earth: 5.1.3535.3218 Author: Werty Script Function: Get longitude, latitude and altitude from a Google Earth screen position using the Google Earth COM API. http://earth.google.com/comapi/index.html #ce ---------------------------------------------------------------------------- ; Note: For simplicity it does not check if GE is initialized, have Google Earth ; running and initialized before running the script, also no error checking. $screen_x = 0 $screen_y = 0 $oGoogleEarth = ObjCreate("GoogleEarth.ApplicationGE") $oPointOnTerrain = $oGoogleEarth.GetPointOnTerrainFromScreenCoords($screen_x, $screen_y) msgbox(0,"Example","Longitude: " & Round($oPointOnTerrain.longitude, 6) & "°" & @CRLF & _ "Latitude: " & Round($oPointOnTerrain.latitude,6) & "°" & @CRLF & _ "Altitude: " & Round($oPointOnTerrain.Altitude, 2) & " Meters") Hopefully enough to get the ball rolling on an UDF, if anyone would like to do that, I'm busy myself with my project now that I got it working. /edit Updated below with GE in GUI. Edited June 9, 2010 by Werty Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Werty Posted June 9, 2010 Author Share Posted June 9, 2010 Update: GE in a GUI... Press ESC to exit, dunno why the close button doesnt work ; Create our GUI $MyGUI = GUICreate("Test", 512, 512) HotKeySet("{ESC}", "On_Exit") ; Create our GE object $oGoogleEarth = ObjCreate("GoogleEarth.ApplicationGE") ; Wait for GE to initialize WinWaitActive("Google Earth") ; Let's hide GE WinSetState("Google Earth", "", @SW_HIDE) ; Get the handle of the GE render window $oRender = $oGoogleEarth.GetRenderHwnd() ; Set our GUI as the Parent for the GE render window _WinAPI_SetParent($oRender, $MyGUI) ; Show our GUI GuiSetState() ; Some random loop to keep it running While 1 WinActive("Test") Wend ; Let's get out of here and close the door after us Func On_Exit() WinClose("Google Earth") Exit EndFunc Needs alot of refinements, like the zooming is wrong, but again kept simple for ease of reading. Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
jaberwacky Posted June 11, 2010 Share Posted June 11, 2010 (edited) Here is what I have so far. This isn't the most bug free code ever so just run it and tell me what you get please. Should we see about getting this topic moved to another forum? expandcollapse popup#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Fileversion=0.0.0.306 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -d #AutoIt3Wrapper_Run_Tidy=y #AutoIt3Wrapper_Run_After=md "%scriptdir%\Versions\%fileversion%" #AutoIt3Wrapper_Run_After=copy "%in%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.au3" #AutoIt3Wrapper_Run_After=copy "%out%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.exe" #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPI.au3> #include <GUIConstantsEX.au3> #include <Misc.au3> _Singleton(@ScriptName) HotKeySet("{ESC}", "On_Exit") Global $oMyError = ObjEvent("Autoit.error", "MyErrorFunc") Global $oGoogleEarth = ObjCreate("GoogleEarth.ApplicationGE") If Not IsObj($oGoogleEarth) Then MsgBox(0, "GoogleEarth", "GEOBJ did not create.") Exit (-1) EndIf WinWaitActive("Google Earth") ; Wait for GE to initialize WinActivate("Google Earth") WinSetState("Google Earth", "", @SW_HIDE) ; Let's hide GE If $oGoogleEarth.IsOnline() <> 1 Then Exit (-1) ElseIf $oGoogleEarth.IsInitialized() <> 1 Then Exit (-1) EndIf main() Func main() #region Create our GUI Local $MyGUI = GUICreate("Google Earth COM", 900, 600) GUICtrlCreateLabel("Initialized?", 710, 10) GUICtrlCreateLabel("Online?", 710, 40) GUICtrlCreateLabel("AutoPilot Speed", 710, 70) GUICtrlCreateLabel("Focus Point Latitude", 710, 100) Local $initEdit = GUICtrlCreateEdit('', 770, 10, 20) Local $onlineEdit = GUICtrlCreateEdit('', 750, 40, 20) Local $AutoSpeedEdit = GUICtrlCreateEdit('', 790, 70, 20) Local $focPtLatEdit = GUICtrlCreateEdit('', 810, 100) #endregion Create our GUI Local $oRender = $oGoogleEarth.GetRenderHwnd() ; Get the handle of the GE render window _WinAPI_SetParent($oRender, $MyGUI) ; Set our GUI as the Parent for the GE render window GUISetState() Local $Struct = GoogleEarth_GetCameraInfo() ; I probably should just return an array here huh? Oh well, just experimenting with new things... MsgBox(0, "GetCameraInfo", DllStructGetData($Struct, "lat")) MsgBox(0, "GetCameraInfo", DllStructGetData($Struct, "long")) MsgBox(0, "GetCameraInfo", DllStructGetData($Struct, "alt")) MsgBox(0, "GetCameraInfo", DllStructGetData($Struct, "mode")) MsgBox(0, "GetCameraInfo", DllStructGetData($Struct, "range")) MsgBox(0, "GetCameraInfo", DllStructGetData($Struct, "tilt")) MsgBox(0, "GetCameraInfo", DllStructGetData($Struct, "az")) GoogleEarth_GetPointOnTerrain(0, 0) GoogleEarth_ZoomTo(36.12, 79.19, 60.5, 60.4, 0.0, 0.0, 1) GoogleEarth_GetPointOnTerrain(0, 0) GoogleEarth_ScreenShot(@ScriptDir & "\screenshot.jpg") Do ; Some random loop to keep it running Sleep(10) Until GUIGetMsg() = $GUI_EVENT_CLOSE $oGoogleEarth.Logout() ProcessClose("googleearth.exe") EndFunc ;==>main Exit ; Let's get out of here and close the door after us Func On_Exit() ConsoleWrite("Exit" & @CRLF) $oGoogleEarth.Logout() ProcessClose("googleearth.exe") EndFunc ;==>On_Exit Func MyErrorFunc() Local $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "COM Error Test", "We intercepted a COM Error!" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext) SetError(1) ; to check for after this function returns EndFunc ;==>MyErrorFunc Func GoogleEarth_GetPointonTerrain($x, $y) Local $opointOnTerrain = $oGoogleEarth.GetPointOnTerrainFromScreenCoords($x, $y) MsgBox(0, "Example", "Longitude: " & Round($opointOnTerrain.longitude, 6) & "°" & @CRLF & _ "Latitude: " & Round($opointOnTerrain.latitude, 6) & "°" & @CRLF & _ "Altitude: " & Round($opointOnTerrain.Altitude, 2) & " Meters") EndFunc ;==>GoogleEarth_GetPointonTerrain Func GoogleEarth_ZoomTo($N, $W, $alt, $range, $tilt, $az, $mode = 1, $speed = 5.0) $oGoogleEarth.SetCameraParams($N, $W, $alt, $mode, $range, $tilt, $az, $speed) ; zoom to a custom locus EndFunc ;==>GoogleEarth_ZoomTo Func GoogleEarth_ScreenShot($directory, $quality = 100) $oGoogleEarth.SaveScreenShot($directory, $quality) ; take a snapshot EndFunc ;==>GoogleEarth_ScreenShot Func GoogleEarth_GetCameraInfo($considerTerrain = True) Local $oCameraInfo = $oGoogleEarth.GetCamera($considerTerrain) Local $Struct = DllStructCreate("double lat;double long;double alt;int mode;double range;double tilt;double az") DllStructSetData($Struct, "lat", $oCameraInfo.FocusPointLatitude) DllStructSetData($Struct, "long", $oCameraInfo.FocusPointLongitude) DllStructSetData($Struct, "alt", $oCameraInfo.FocusPointAltitude) DllStructSetData($Struct, "mode", $oCameraInfo.FocusPointAltitudeMode) DllStructSetData($Struct, "range", $oCameraInfo.Range) DllStructSetData($Struct, "tilt", $oCameraInfo.Tilt) DllStructSetData($Struct, "az", $oCameraInfo.Azimuth) Return $Struct EndFunc ;==>GoogleEarth_GetCameraInfo Unrelated idea: The ultimate in social coding -- an IDE that broadcasts everything that is typed into the IDE to other coders. It would make you more aware of what you type? Either that or I might start using the AutoIt forums to to code my scripts. I might as well as many times as I edit my scripts here! Edited June 11, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
pierrotm777 Posted June 12, 2010 Share Posted June 12, 2010 Cool Link to comment Share on other sites More sharing options...
ngocs2tron Posted November 6, 2010 Share Posted November 6, 2010 i have 1 error: GEOBJ did not create. Link to comment Share on other sites More sharing options...
Werty Posted November 6, 2010 Author Share Posted November 6, 2010 i have 1 error: GEOBJ did not create.Try posting your code.Silly question, but you do have google earth installed yes ? Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now