Accueil > > > PILOTER GOOGLEEARTH AVEC SES API
PILOTER GOOGLEEARTH AVEC SES API
Information sur la source
Description
Petit code sans prétention montrant par une utilisation très simple le controle de GoogleEarth via ses API. Deux petits exemples pour charger des données KML soit via la fonction LoadKmlData ou OpenKMLFile. Deux de déplacement et récupération de coordonnées. Et deux exemple de sélection de feature. Enfin deux "Bidouilles" pour sauver un fichier KML à partir d'un feature ou supprimer un feature. Le Zip contient uniquement le fichier KML Exemple. Pour les Grand débutant : pour que la source fonctionne ne pas oublié de rajouter dans Projet / Références / "Earth 1.0 type library" Voir copie écran.
Source
-
- 'A mettre dans une Feuille avec 8 boutons
- Option explicit
-
- 'Exemple de chargement de données KML dans googleEarth
- Private Sub Command1_Click()
- Dim GEI As ApplicationGE
- Dim Fichier As String
-
- Set GEI = CreateObject("GoogleEarth.ApplicationGE")
-
- 'Attente que GoogleEarth soit initialisé
- While (GEI.IsInitialized = 0)
- DoEvents
- Wend
- Fichier = App.Path & "\Genève.kml"
-
- Call GEI.OpenKmlFile(Fichier, 1) ' 1= pas de message dans GoogleEarth si le fichier n'existe pas par exemple
-
- End Sub
-
- Private Sub Command2_Click()
- Dim GEI As ApplicationGE
- Dim KMLData As String
-
-
- Set GEI = CreateObject("GoogleEarth.ApplicationGE")
-
- 'Attente que GoogleEarth soit initialisé
- While (GEI.IsInitialized = 0)
- DoEvents
- Wend
-
- 'Initialisation données KML
- KMLData = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
- "<kml xmlns=""http://earth.google.com/kml/2.1"">" & _
- "<Placemark>" & _
- "<name>Geneva</name>" & _
- "<LookAt>" & _
- "<longitude>6.156182706892176</longitude>" & _
- "<latitude>46.20746317320977</latitude>" & _
- "<altitude>0</altitude>" & _
- "<range>316.3662914479763</range>" & _
- "<tilt>0</tilt>" & _
- "<heading>6.199453434125936</heading>" & _
- "</LookAt>" & _
- "<Point>" & _
- "<coordinates>6.156019183879536,46.20743386584116,0</coordinates>" & _
- "</Point>" & _
- "</Placemark>" & _
- "</kml>"
-
- 'Chargement données dans GE
- GEI.LoadKmlData KMLData
-
- End Sub
-
- 'Exemple de récupération de coordonnées de point et d'altitude
- Private Sub Command3_Click()
- Dim GEI As ApplicationGE
- Dim PointOnTerrain() As Double
- Dim PositionCherché(2) As Double
- Dim Repeat As Integer
- Dim Epsilon As Double
- Dim LongDiff As Double
- Dim LatDiff As Double
-
- 'Initialisation
- Epsilon = 0.0005
-
- 'Coordonnées du mont Blanc
- PositionCherché(0) = 45.8325541
- PositionCherché(1) = 6.86437217
-
- Set GEI = CreateObject("GoogleEarth.ApplicationGE")
-
- 'Attente que GoogleEarth soit initialisé
- While (GEI.IsInitialized = 0)
- DoEvents
- Wend
-
-
- 'Fixe le mode Elevation à 1 ( Activation relief)
- GEI.ElevationExaggeration = 1 'Si différent de 0, alors coords[2] est fixée à la vraie altitude du terrain.
-
-
-
-
-
- 'Récupération de données de point centre écran les
- Do
- 'Positionne la caméra sur le Mont Blanc (La vitesse est fixé à 5 = Maxi donc pas d'effet de transition
- Call GEI.SetCameraParams(PositionCherché(0), PositionCherché(1), 0, RelativeToGroundAltitudeGE, 100, 0, 0, 5)
-
- PointOnTerrain = GEI.GetPointOnTerrainFromScreenCoords(0, 0)
- 'Attente que le processus de striming soit terminé sur la zone concerné
- While (GEI.StreamingProgressPercentage < 100)
- DoEvents
- Wend
- LongDiff = Abs(PositionCherché(1) - PointOnTerrain(1))
- LatDiff = Abs(PositionCherché(0) - PointOnTerrain(0))
- Repeat = Repeat + 1
- 'Controle que la position est bien celle demandée. Repeeat permet déviter de blocquer la procédure
- 'avec une limite à 100 itérations
- Loop While (LongDiff > Epsilon Or LatDiff > Epsilon Or PointOnTerrain(2) < 0) And Repeat < 100
-
-
-
- MsgBox "Altitude Mont Blanc dans GoogleEarth " & PointOnTerrain(2)
-
- End Sub
-
- 'Affiche la position courante d'un repère présent dans GE
- Private Sub Command4_Click()
- Dim GEI As ApplicationGE
- Dim Feat As FeatureGE
- Dim Child As FeatureCollectionGE
- Dim CameraInfo As CameraInfoGE
-
-
- Set GEI = CreateObject("GoogleEarth.ApplicationGE")
-
- 'Attente que GoogleEarth soit initialisé
- While (GEI.IsInitialized = 0)
- DoEvents
- Wend
-
- ' Charge la position default. Cette fonction permet de récupérer les infos en donnant le nom du repère
- Set Feat = GEI.GetFeatureByName("default")
- 'Set Child = Feat.GetChildren
- 'Debug.Print Child.Count
-
- 'Si elle a une vue on y va
- If Feat.HasView Then
- Call GEI.SetFeatureView(Feat, 5)
- End If
-
- 'Retourne la position courant
- Set CameraInfo = GEI.GetCamera(1)
-
- MsgBox "Latitude=" & CameraInfo.FocusPointLatitude & " Longitude=" & CameraInfo.FocusPointLongitude
-
- End Sub
-
- 'fonction pour récupérér un feature GE depuis la base de données primaire
- Private Sub Command5_Click()
- Dim Indice As Long
- Dim GEI As ApplicationGE
- Dim Feat As FeatureGE
- Dim Child As FeatureCollectionGE
- Dim CameraInfo As CameraInfoGE
-
-
- Set GEI = CreateObject("GoogleEarth.ApplicationGE")
-
- 'Attente que GoogleEarth soit initialisé
- While (GEI.IsInitialized = 0)
- DoEvents
- Wend
-
- 'Racine du layersdatabase
- 'Récupère les enfants
- Set Child = GEI.GetLayersDatabases.Item(1).GetChildren
- For Indice = 1 To Child.Count
- 'Si elle a une vue et si c'est bien ce qui m'intéresse on y va
- If Child.Item(Indice).HasView And InStr(Child.Item(Indice).Name, "Élection présidentielle France 2007") Then
- Call GEI.SetFeatureView(Child.Item(Indice), 5)
- End If
- Next Indice
-
- End Sub
-
- 'fonction pour récupérer un feature GE depuis son nom
- Private Sub Command6_Click()
-
- Dim Indice As Long
- Dim GEI As ApplicationGE
- Dim Feat As FeatureGE
- Dim Child As FeatureCollectionGE
- Dim CameraInfo As CameraInfoGE
-
-
- Set GEI = CreateObject("GoogleEarth.ApplicationGE")
-
-
-
- 'Attente que GoogleEarth soit initialisé
- While (GEI.IsInitialized = 0)
- DoEvents
- Wend
-
-
-
-
-
- 'Récupère les enfants du feature "Geneva" selon exemple
- Set Feat = GEI.GetFeatureByName("Geneva")
- Call Feat.Highlight
- Call GEI.SetFeatureView(Feat, 5)
-
-
- Set Child = Feat.GetChildren
- For Indice = 1 To Child.Count
- 'Si elle a une vue et si c'est bien ce qui m'intéresse on y va
- Debug.Print Child.Item(Indice).Name
- 'Rend visible le Feature
- Child.Item(Indice).Visibility = True
-
- ' Se déplace sur le feature
- Call GEI.SetFeatureView(Child.Item(Indice), 1)
-
- Call Sleep(1000)
-
- 'Attente que le processus de striming soit terminé sur la zone concerné
- While (GEI.StreamingProgressPercentage < 100)
- DoEvents
- Wend
- Call Child.Item(Indice).Highlight
-
- Next Indice
-
-
- End Sub
-
- 'Fonction pour sauver le feature sous un format KML
- Private Sub Command7_Click()
- SauverFeature "Geneva", "C:\tmp\test"
- End Sub
-
- Private Sub Command8_Click()
- DeleteFeature "Geneva"
- End Sub
-
- '------------------------------------------------
- ' CODE A RAJOUTER DANS UN MODULE
- '------------------------------------------------
-
- Option Explicit
-
- Const HWND_TOPMOST = -1&
- Const HWND_NOTOPMOST = -2&
- Const HWND_TOP = 0
- Const SWP_NOSIZE = &H1&
- Const SWP_NOMOVE = &H2&
- Const SWP_NOACTIVATE = &H10&
- Const SWP_SHOWWINDOW = &H40&
- Const THREAD_BASE_PRIORITY_MAX = 2
- Const HIGH_PRIORITY_CLASS = &H80
-
-
-
- Declare Sub SetWindowPos Lib "User32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
-
-
- 'Declaration fonction sleep
- Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
-
-
- Private Declare Function IsWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
- Private Declare Function MapVirtualKey Lib "user32.dll" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
- Private Declare Function GetKeyboardState Lib "user32.dll" (ByRef pbKeyState As Byte) As Long
- Private Declare Function SetKeyboardState Lib "user32.dll" (ByRef lppbKeyState As Byte) As Long
- Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
- 'Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- 'Private Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
- Private Declare Function AttachThreadInput Lib "user32.dll" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
- Private Declare Function GetCurrentThreadId Lib "kernel32.dll" () As Long
- Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
-
-
- Private Const GW_CHILD As Long = 5
-
- Private Const WM_KEYDOWN As Long = &H100
- Private Const WM_KEYUP As Long = &H101
- Private Const WM_SYSKEYDOWN As Long = &H104
- Private Const WM_SYSKEYUP As Long = &H105
-
- ' Fonction venant à l'origine de www.vbfrance.com
- ' http://www.vbfrance.com/codes/SENDKEYSEX-SIMULER-TOUCHE-DANS-FENETRE-PRECISE_41974.aspx
- ' par Renfield
- Public Sub SendKeysEx(ByVal vhTargetWnd As Long, ByVal veKey As VBRUN.KeyCodeConstants, Optional ByVal veShift As VBRUN.ShiftConstants, Optional ByVal vbExtendedKey As Boolean = False)
- Dim xbMemBuffer(255) As Byte
- Dim xbNewBuffer(255) As Byte
- Dim nKeyParam As Long
- Dim nTargetThreadID As Long
- '# Si la cible est valide...
- If IsWindow(vhTargetWnd) Then
- nTargetThreadID = GetWindowThreadProcessId(vhTargetWnd, ByVal 0&)
- AttachThreadInput GetCurrentThreadId, nTargetThreadID, 1&
-
- nKeyParam = MapVirtualKey(veKey, 0) * &H10000
- If vbExtendedKey Then
- nKeyParam = nKeyParam Or &H1000000 '# bit 24
- End If
-
- '# On mémorise l'etat du clavier
- GetKeyboardState xbMemBuffer(0)
-
- If (veShift And vbShiftMask) <> 0 Then
- xbNewBuffer(vbKeyShift) = &H80
- End If
- If (veShift And vbCtrlMask) <> 0 Then
- xbNewBuffer(vbKeyControl) = &H80
- End If
-
- '# On place notre image du clavier en mémoire
- SetKeyboardState xbNewBuffer(0)
-
- '# On prévient la cible que le clavier a été manipulé
- PostMessage vhTargetWnd, WM_KEYDOWN, veKey, nKeyParam
- PostMessage vhTargetWnd, WM_KEYUP, veKey, nKeyParam Or &HC0000000
-
- '# On 'force' la cible a prendre en compte les changements effectués
- Sleep 1
-
- '# Il ne nous reste plus alors qu'a restaurer l'image du clavier.
- SetKeyboardState xbMemBuffer(0)
- AttachThreadInput GetCurrentThreadId, nTargetThreadID, 0&
- End If
- End Sub
-
-
- '-------------------------------------------------------------------------------------------------------------
- 'Fonction permetant de sauver un feature dans un Fichier KML
- 'Ce fichier étant un format Ascii, il sera par la suite facile de le traiter pour récupérer les informations
- 'Seul moyen trouvé pour le moment pour avoir accès aux informations.
- '
- ' Retourne 1 si Feature trouvé et sauvegardé 0 dans le cas contraire
- '
- ' Note la fonction utilise sendkeys et donc elle est dépendante de la langue (CTL+S, ALT+E etc ..)
- '
- ' Pour le moment j'ai rien trouvé de mieux désolé.
- '-------------------------------------------------------------------------------------------------------------
-
- Function SauverFeature(NomDuFeature As String, Optional Fichier As String) As Long
-
- Dim Indice As Long
- Dim GEI As ApplicationGE
- Dim Feat As FeatureGE
- Dim Child As FeatureCollectionGE
- Dim CameraInfo As CameraInfoGE
- Dim retval As Long ' return value
- Dim hwnd As Long
-
-
- Set GEI = CreateObject("GoogleEarth.ApplicationGE")
-
-
-
- 'Attente que GoogleEarth soit initialisé
- While (GEI.IsInitialized = 0)
- DoEvents
- Wend
-
-
- hwnd = GEI.GetMainHwnd
-
- Sleep 1000
-
-
- 'Récupère un feature par son nom
- Set Feat = GEI.GetFeatureByName(NomDuFeature)
-
- 'Si le feature à été trouvé
- If Feat Is Nothing Then
- SauverFeature = 0
- Else
-
- 'Sélectionne le Feature
- Call Feat.Highlight
-
-
- '# Ctrl + S
- 'SendKeys "^s"
- SendKeysEx hwnd, vbKeyS, vbCtrlMask
-
- 'Normalement là on ouvre une autre fenetre donc utilise sendkeys car sinon il faut récupérer le handle
-
-
- 'Rajoute extension .kml si pas présente
- If Len(Fichier) Then
- Debug.Print InStr(Len(Fichier) - 4, Fichier, ".kml")
- If InStr(Len(Fichier) - 4, Fichier, ".kml") = 0 Then
- Fichier = Fichier & ".kml"
- End If
-
- SendKeys Fichier
- End If
-
-
- 'Alt+E
- SendKeys "%(E)"
- 'au cas ou le fichier existe déjà enter
- SendKeys "{ENTER}"
-
- ' Se déplace sur le feature
- Call GEI.SetFeatureView(Feat, 5)
-
- SauverFeature = 1
-
- End If
-
- End Function
-
- Function DeleteFeature(NomDuFeature As String) As Long
-
- Dim Indice As Long
- Dim GEI As ApplicationGE
- Dim Feat As FeatureGE
- Dim Child As FeatureCollectionGE
- Dim CameraInfo As CameraInfoGE
- Dim hwnd As Long
-
-
- Set GEI = CreateObject("GoogleEarth.ApplicationGE")
-
-
-
- 'Attente que GoogleEarth soit initialisé
- While (GEI.IsInitialized = 0)
- DoEvents
- Wend
-
- 'Handle de la fenêtre
- hwnd = GEI.GetMainHwnd
-
- Sleep 1000
-
-
- 'Récupère un feature par son nom
- Set Feat = GEI.GetFeatureByName(NomDuFeature)
-
- 'Si le feature à été trouvé
- If Feat Is Nothing Then
- MsgBox "Rien a supprimer"
- DeleteFeature = 0
- Else
-
- 'Sélectionne le Feature
- Call Feat.Highlight
-
-
- ' DELETE
- ' SendKeys "{DELETE}"
- SendKeysEx hwnd, vbKeyDelete
- ' Valid
- SendKeys "{ENTER}"
-
- DeleteFeature = 1
-
- End If
-
- End Function
'A mettre dans une Feuille avec 8 boutons
Option explicit
'Exemple de chargement de données KML dans googleEarth
Private Sub Command1_Click()
Dim GEI As ApplicationGE
Dim Fichier As String
Set GEI = CreateObject("GoogleEarth.ApplicationGE")
'Attente que GoogleEarth soit initialisé
While (GEI.IsInitialized = 0)
DoEvents
Wend
Fichier = App.Path & "\Genève.kml"
Call GEI.OpenKmlFile(Fichier, 1) ' 1= pas de message dans GoogleEarth si le fichier n'existe pas par exemple
End Sub
Private Sub Command2_Click()
Dim GEI As ApplicationGE
Dim KMLData As String
Set GEI = CreateObject("GoogleEarth.ApplicationGE")
'Attente que GoogleEarth soit initialisé
While (GEI.IsInitialized = 0)
DoEvents
Wend
'Initialisation données KML
KMLData = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
"<kml xmlns=""http://earth.google.com/kml/2.1"">" & _
"<Placemark>" & _
"<name>Geneva</name>" & _
"<LookAt>" & _
"<longitude>6.156182706892176</longitude>" & _
"<latitude>46.20746317320977</latitude>" & _
"<altitude>0</altitude>" & _
"<range>316.3662914479763</range>" & _
"<tilt>0</tilt>" & _
"<heading>6.199453434125936</heading>" & _
"</LookAt>" & _
"<Point>" & _
"<coordinates>6.156019183879536,46.20743386584116,0</coordinates>" & _
"</Point>" & _
"</Placemark>" & _
"</kml>"
'Chargement données dans GE
GEI.LoadKmlData KMLData
End Sub
'Exemple de récupération de coordonnées de point et d'altitude
Private Sub Command3_Click()
Dim GEI As ApplicationGE
Dim PointOnTerrain() As Double
Dim PositionCherché(2) As Double
Dim Repeat As Integer
Dim Epsilon As Double
Dim LongDiff As Double
Dim LatDiff As Double
'Initialisation
Epsilon = 0.0005
'Coordonnées du mont Blanc
PositionCherché(0) = 45.8325541
PositionCherché(1) = 6.86437217
Set GEI = CreateObject("GoogleEarth.ApplicationGE")
'Attente que GoogleEarth soit initialisé
While (GEI.IsInitialized = 0)
DoEvents
Wend
'Fixe le mode Elevation à 1 ( Activation relief)
GEI.ElevationExaggeration = 1 'Si différent de 0, alors coords[2] est fixée à la vraie altitude du terrain.
'Récupération de données de point centre écran les
Do
'Positionne la caméra sur le Mont Blanc (La vitesse est fixé à 5 = Maxi donc pas d'effet de transition
Call GEI.SetCameraParams(PositionCherché(0), PositionCherché(1), 0, RelativeToGroundAltitudeGE, 100, 0, 0, 5)
PointOnTerrain = GEI.GetPointOnTerrainFromScreenCoords(0, 0)
'Attente que le processus de striming soit terminé sur la zone concerné
While (GEI.StreamingProgressPercentage < 100)
DoEvents
Wend
LongDiff = Abs(PositionCherché(1) - PointOnTerrain(1))
LatDiff = Abs(PositionCherché(0) - PointOnTerrain(0))
Repeat = Repeat + 1
'Controle que la position est bien celle demandée. Repeeat permet déviter de blocquer la procédure
'avec une limite à 100 itérations
Loop While (LongDiff > Epsilon Or LatDiff > Epsilon Or PointOnTerrain(2) < 0) And Repeat < 100
MsgBox "Altitude Mont Blanc dans GoogleEarth " & PointOnTerrain(2)
End Sub
'Affiche la position courante d'un repère présent dans GE
Private Sub Command4_Click()
Dim GEI As ApplicationGE
Dim Feat As FeatureGE
Dim Child As FeatureCollectionGE
Dim CameraInfo As CameraInfoGE
Set GEI = CreateObject("GoogleEarth.ApplicationGE")
'Attente que GoogleEarth soit initialisé
While (GEI.IsInitialized = 0)
DoEvents
Wend
' Charge la position default. Cette fonction permet de récupérer les infos en donnant le nom du repère
Set Feat = GEI.GetFeatureByName("default")
'Set Child = Feat.GetChildren
'Debug.Print Child.Count
'Si elle a une vue on y va
If Feat.HasView Then
Call GEI.SetFeatureView(Feat, 5)
End If
'Retourne la position courant
Set CameraInfo = GEI.GetCamera(1)
MsgBox "Latitude=" & CameraInfo.FocusPointLatitude & " Longitude=" & CameraInfo.FocusPointLongitude
End Sub
'fonction pour récupérér un feature GE depuis la base de données primaire
Private Sub Command5_Click()
Dim Indice As Long
Dim GEI As ApplicationGE
Dim Feat As FeatureGE
Dim Child As FeatureCollectionGE
Dim CameraInfo As CameraInfoGE
Set GEI = CreateObject("GoogleEarth.ApplicationGE")
'Attente que GoogleEarth soit initialisé
While (GEI.IsInitialized = 0)
DoEvents
Wend
'Racine du layersdatabase
'Récupère les enfants
Set Child = GEI.GetLayersDatabases.Item(1).GetChildren
For Indice = 1 To Child.Count
'Si elle a une vue et si c'est bien ce qui m'intéresse on y va
If Child.Item(Indice).HasView And InStr(Child.Item(Indice).Name, "Élection présidentielle France 2007") Then
Call GEI.SetFeatureView(Child.Item(Indice), 5)
End If
Next Indice
End Sub
'fonction pour récupérer un feature GE depuis son nom
Private Sub Command6_Click()
Dim Indice As Long
Dim GEI As ApplicationGE
Dim Feat As FeatureGE
Dim Child As FeatureCollectionGE
Dim CameraInfo As CameraInfoGE
Set GEI = CreateObject("GoogleEarth.ApplicationGE")
'Attente que GoogleEarth soit initialisé
While (GEI.IsInitialized = 0)
DoEvents
Wend
'Récupère les enfants du feature "Geneva" selon exemple
Set Feat = GEI.GetFeatureByName("Geneva")
Call Feat.Highlight
Call GEI.SetFeatureView(Feat, 5)
Set Child = Feat.GetChildren
For Indice = 1 To Child.Count
'Si elle a une vue et si c'est bien ce qui m'intéresse on y va
Debug.Print Child.Item(Indice).Name
'Rend visible le Feature
Child.Item(Indice).Visibility = True
' Se déplace sur le feature
Call GEI.SetFeatureView(Child.Item(Indice), 1)
Call Sleep(1000)
'Attente que le processus de striming soit terminé sur la zone concerné
While (GEI.StreamingProgressPercentage < 100)
DoEvents
Wend
Call Child.Item(Indice).Highlight
Next Indice
End Sub
'Fonction pour sauver le feature sous un format KML
Private Sub Command7_Click()
SauverFeature "Geneva", "C:\tmp\test"
End Sub
Private Sub Command8_Click()
DeleteFeature "Geneva"
End Sub
'------------------------------------------------
' CODE A RAJOUTER DANS UN MODULE
'------------------------------------------------
Option Explicit
Const HWND_TOPMOST = -1&
Const HWND_NOTOPMOST = -2&
Const HWND_TOP = 0
Const SWP_NOSIZE = &H1&
Const SWP_NOMOVE = &H2&
Const SWP_NOACTIVATE = &H10&
Const SWP_SHOWWINDOW = &H40&
Const THREAD_BASE_PRIORITY_MAX = 2
Const HIGH_PRIORITY_CLASS = &H80
Declare Sub SetWindowPos Lib "User32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
'Declaration fonction sleep
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function IsWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function MapVirtualKey Lib "user32.dll" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function GetKeyboardState Lib "user32.dll" (ByRef pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32.dll" (ByRef lppbKeyState As Byte) As Long
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Private Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function AttachThreadInput Lib "user32.dll" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32.dll" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
Private Const GW_CHILD As Long = 5
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_KEYUP As Long = &H101
Private Const WM_SYSKEYDOWN As Long = &H104
Private Const WM_SYSKEYUP As Long = &H105
' Fonction venant à l'origine de www.vbfrance.com
' http://www.vbfrance.com/codes/SENDKEYSEX-SIMULER-TOUCHE-DANS-FENETRE-PRECISE_41974.aspx
' par Renfield
Public Sub SendKeysEx(ByVal vhTargetWnd As Long, ByVal veKey As VBRUN.KeyCodeConstants, Optional ByVal veShift As VBRUN.ShiftConstants, Optional ByVal vbExtendedKey As Boolean = False)
Dim xbMemBuffer(255) As Byte
Dim xbNewBuffer(255) As Byte
Dim nKeyParam As Long
Dim nTargetThreadID As Long
'# Si la cible est valide...
If IsWindow(vhTargetWnd) Then
nTargetThreadID = GetWindowThreadProcessId(vhTargetWnd, ByVal 0&)
AttachThreadInput GetCurrentThreadId, nTargetThreadID, 1&
nKeyParam = MapVirtualKey(veKey, 0) * &H10000
If vbExtendedKey Then
nKeyParam = nKeyParam Or &H1000000 '# bit 24
End If
'# On mémorise l'etat du clavier
GetKeyboardState xbMemBuffer(0)
If (veShift And vbShiftMask) <> 0 Then
xbNewBuffer(vbKeyShift) = &H80
End If
If (veShift And vbCtrlMask) <> 0 Then
xbNewBuffer(vbKeyControl) = &H80
End If
'# On place notre image du clavier en mémoire
SetKeyboardState xbNewBuffer(0)
'# On prévient la cible que le clavier a été manipulé
PostMessage vhTargetWnd, WM_KEYDOWN, veKey, nKeyParam
PostMessage vhTargetWnd, WM_KEYUP, veKey, nKeyParam Or &HC0000000
'# On 'force' la cible a prendre en compte les changements effectués
Sleep 1
'# Il ne nous reste plus alors qu'a restaurer l'image du clavier.
SetKeyboardState xbMemBuffer(0)
AttachThreadInput GetCurrentThreadId, nTargetThreadID, 0&
End If
End Sub
'-------------------------------------------------------------------------------------------------------------
'Fonction permetant de sauver un feature dans un Fichier KML
'Ce fichier étant un format Ascii, il sera par la suite facile de le traiter pour récupérer les informations
'Seul moyen trouvé pour le moment pour avoir accès aux informations.
'
' Retourne 1 si Feature trouvé et sauvegardé 0 dans le cas contraire
'
' Note la fonction utilise sendkeys et donc elle est dépendante de la langue (CTL+S, ALT+E etc ..)
'
' Pour le moment j'ai rien trouvé de mieux désolé.
'-------------------------------------------------------------------------------------------------------------
Function SauverFeature(NomDuFeature As String, Optional Fichier As String) As Long
Dim Indice As Long
Dim GEI As ApplicationGE
Dim Feat As FeatureGE
Dim Child As FeatureCollectionGE
Dim CameraInfo As CameraInfoGE
Dim retval As Long ' return value
Dim hwnd As Long
Set GEI = CreateObject("GoogleEarth.ApplicationGE")
'Attente que GoogleEarth soit initialisé
While (GEI.IsInitialized = 0)
DoEvents
Wend
hwnd = GEI.GetMainHwnd
Sleep 1000
'Récupère un feature par son nom
Set Feat = GEI.GetFeatureByName(NomDuFeature)
'Si le feature à été trouvé
If Feat Is Nothing Then
SauverFeature = 0
Else
'Sélectionne le Feature
Call Feat.Highlight
'# Ctrl + S
'SendKeys "^s"
SendKeysEx hwnd, vbKeyS, vbCtrlMask
'Normalement là on ouvre une autre fenetre donc utilise sendkeys car sinon il faut récupérer le handle
'Rajoute extension .kml si pas présente
If Len(Fichier) Then
Debug.Print InStr(Len(Fichier) - 4, Fichier, ".kml")
If InStr(Len(Fichier) - 4, Fichier, ".kml") = 0 Then
Fichier = Fichier & ".kml"
End If
SendKeys Fichier
End If
'Alt+E
SendKeys "%(E)"
'au cas ou le fichier existe déjà enter
SendKeys "{ENTER}"
' Se déplace sur le feature
Call GEI.SetFeatureView(Feat, 5)
SauverFeature = 1
End If
End Function
Function DeleteFeature(NomDuFeature As String) As Long
Dim Indice As Long
Dim GEI As ApplicationGE
Dim Feat As FeatureGE
Dim Child As FeatureCollectionGE
Dim CameraInfo As CameraInfoGE
Dim hwnd As Long
Set GEI = CreateObject("GoogleEarth.ApplicationGE")
'Attente que GoogleEarth soit initialisé
While (GEI.IsInitialized = 0)
DoEvents
Wend
'Handle de la fenêtre
hwnd = GEI.GetMainHwnd
Sleep 1000
'Récupère un feature par son nom
Set Feat = GEI.GetFeatureByName(NomDuFeature)
'Si le feature à été trouvé
If Feat Is Nothing Then
MsgBox "Rien a supprimer"
DeleteFeature = 0
Else
'Sélectionne le Feature
Call Feat.Highlight
' DELETE
' SendKeys "{DELETE}"
SendKeysEx hwnd, vbKeyDelete
' Valid
SendKeys "{ENTER}"
DeleteFeature = 1
End If
End Function
Conclusion
Descriptif API GoogleEarth (en anglais) http://earth.google.com/comapi/interfaceIApplicati onGE.html
Comme indiqué sur le site de GoogleEarth cette API est pour le moment au stade BETA. J'espère qu'elle évoluera avec le temps. Les méthodes de récupération d'information étant plus que limitées pour le moment.
Historique
- 24 octobre 2006 10:43:51 :
- Ajout d'un exemple un peu plus évolué avec déplacement du point de vision et récupéartion des coordonnées du centre écran. Bon normalement on devrait avoir l'altitude du Mont Blanc entre 4810 et 4807 (Merci pas de polémique...) Bon ici c'est plus 4086 ... Le but n'étant pas de déclencher une polémique sur se sujet merci d'en rester à ce qui nous intéresse dans ce Post...
- 24 octobre 2006 11:53:58 :
- Voir Remarque Renfield
- 24 octobre 2006 12:53:13 :
- J'ai modifié la relecture d'un point car même en attentant la fin streaming la coordonnée n'était pas forcément la même. Il n'y a pas d'attente entre SetCameraParams et la suite du programme. Là ca doit être bon.
- 24 octobre 2006 13:42:30 :
- Modif sur position si GE pas chargé
- 24 octobre 2006 14:17:05 :
- Ajout exemple 4
- 26 octobre 2006 09:56:58 :
- Modif sur code 3 car problème de latence entre position demandée et position retournée
- 10 mai 2007 16:38:40 :
- Ajout d'une fonction permetant de sauver un feature dans un Fichier KML. Cette fonction est une béquille en attendant une solution via L'api (Si elle arrive un jour, ce qui semble mal partie ( version béta 4.1 dispo et toujours pas d'évolution)
Le fichier KML étant un format Ascii, il sera par la suite facile de le traiter pour récupérer les informations c'est le seul moyen trouvé pour le moment pour avoir accès aux informations.
Si vous avez mieux ...
- 10 mai 2007 17:36:09 :
- Ajout fonction DeleteFeature
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Google Map API ? ou autre ? [ par C35 ]
Bonjour,Je cherche une fonction qui retournerait une liste de ville en fonction :- d'une ville donnée- d'un nombre de kilomètresLa fonction retournera
base de donnee et google earth [ par sabrachatilla ]
salutje suis débutante dans le domaine des forumes et j ai une question à poser. je veux connecter google earth à une base de donnée pour enregistre
Créer un fichier kmz pour Google Earth [ par steffy64 ]
Bonjour, je ne sais pas très bien dans quel thème poser cette question. J'ai ouvert un fichier sous google earth, et j'ai été surprise de voir qu'on
Utiliser l'api google map pour vb.net [ par dratcliff ]
bonjours, je suis peut etre en train de poser une question bête, mais je voudrais effectuer des recherches via l'api google map en dans un programme e
[BAR]Utilisation de l'API GOOGLE MAP sous Access 2003 [ par MeShoggun ]
Bonjour à tous, et tout d'abord un grand merci pour la qualité des informations disponibles sur les différents forums. Je développe actuellement une
Google Maps API Javascript [ par mimimiao ]
[^^clinoeil3] bonjour tout le monde j'ai un projet a réaliser et pour ceci j'ai a utiliser l'api google map javascript dans du html je voudrais savoir
Problème d'intégration de l'API Youtube [ par aloisio11 ]
Bonjour à tous,Je voudrais créer un application pour envoyer des vidéos sur mon compte Youtube automatiquement.Je voulais donc utiliser l'API de Youtu
PictureBox [ par KIPRE74 ]
Bonjour à tous !Je développe une petite application pour lire mes fichier kml avec google earth, et j'ai deux soucis :1- lorsque je sélection mon fich
utilisation de l'API sleep en vb6 [ par yvesdudu ]
bonjour à tous, J'ai voulu utiliser l'API sleep dans mon code mais je n'arrive pas à avoir une tempo réelle en fonction du code . Voilà mon bout de co
|
Derniers Blogs
SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko
Logiciels
PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|