Advertisement
Thunder-Menu

StreetViewGoogleMap.ps1

Apr 11th, 2023 (edited)
1,198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 4.23 KB | Source Code | 0 0
  1. Add-Type -AssemblyName System.Windows.Forms
  2. Add-Type -AssemblyName System.Drawing
  3. Add-Type -AssemblyName System.Web
  4.  
  5. $form = New-Object System.Windows.Forms.Form
  6. $form.Size = New-Object System.Drawing.Size(800,600)
  7.  
  8. $webBrowser = New-Object System.Windows.Forms.WebBrowser
  9. $webBrowser.Dock = 'Fill'
  10. $webBrowser.ScriptErrorsSuppressed = $true
  11. $webBrowser.AllowWebBrowserDrop = $false
  12. $webBrowser.IsWebBrowserContextMenuEnabled = $false
  13. $webBrowser.WebBrowserShortcutsEnabled = $false
  14.  
  15.  
  16. # Coordonnées par défaut (Paris)
  17. $global:defaultLatitude = 48.8566
  18. $global:defaultLongitude = 2.3522
  19.  
  20.  
  21. # Création de la fenêtre principale
  22. $mainWindow = New-Object System.Windows.Forms.Form
  23. $mainWindow.Text = 'Google Maps'
  24. $mainWindow.ClientSize = New-Object System.Drawing.Size(550, 500)
  25. $mainWindow.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
  26. $mainWindow.MaximizeBox = $false
  27. $mainWindow.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
  28.  
  29. # Création du contrôle WebBrowser
  30. $webBrowser = New-Object System.Windows.Forms.WebBrowser
  31. $webBrowser.Dock = [System.Windows.Forms.DockStyle]::Fill
  32. $webBrowser.ScriptErrorsSuppressed = $true
  33. $webBrowser.Navigate("https://www.google.com/maps?q=&layer=c&cbll=$global:defaultLatitude,$global:defaultLongitude&cbp=11.54,,0,0,-15")
  34.  
  35. # Création de la zone de recherche
  36. $searchBox = New-Object System.Windows.Forms.TextBox
  37. $searchBox.Location = New-Object System.Drawing.Point(200, 8)
  38. $searchBox.Size = New-Object System.Drawing.Size(100, 20)
  39. $searchBox.Add_KeyDown({
  40.     if ($_.KeyCode -eq 'Enter') {
  41.         $webBrowser.Navigate("https://www.google.com/maps?q=" + [System.Web.HttpUtility]::UrlEncode($searchBox.Text))
  42.     }
  43. })
  44.  
  45. # Bouton "Retour à Street View"
  46. $returnToStreetViewButton = New-Object System.Windows.Forms.Button
  47. $returnToStreetViewButton.Location = New-Object System.Drawing.Point(390, 8)
  48. $returnToStreetViewButton.Size = New-Object System.Drawing.Size(150, 25)
  49. $returnToStreetViewButton.Text = 'Return to Street View'
  50. $returnToStreetViewButton.Add_Click({
  51. $url = "https://www.google.com/maps?q=&layer=c&cbll=$global:defaultLatitude,$global:defaultLongitude&cbp=11.54,,0,0,-15"
  52. $webBrowser.Navigate($url)
  53. })
  54.  
  55. $altitudeLabel = New-Object System.Windows.Forms.Label
  56. $altitudeLabel.Location = New-Object System.Drawing.Point(10, 40)
  57. $altitudeLabel.AutoSize = $true
  58.  
  59. $longitudeLabel = New-Object System.Windows.Forms.Label
  60. $longitudeLabel.Location = New-Object System.Drawing.Point(10, 70)
  61. $longitudeLabel.AutoSize = $true
  62.  
  63. $latitudeLabel = New-Object System.Windows.Forms.Label
  64. $latitudeLabel.Location = New-Object System.Drawing.Point(10, 100)
  65. $latitudeLabel.AutoSize = $true
  66.  
  67. $webBrowser.Add_Navigated({
  68.     if ($webBrowser.Url.AbsoluteUri -match '/@([0-9.-]+),([0-9.-]+),') {
  69.         $lat = $matches[1]
  70.         $long = $matches[2]
  71.         $searchBox.Text = ''
  72.  
  73.         # Extraction de l'altitude à partir de l'URL
  74.         if ($webBrowser.Url.AbsoluteUri -match '/@([0-9.-]+),([0-9.-]+),([0-9]+z)') {
  75.             $altitude = $matches[3]
  76.             $altitudeLabel.Text = "Altitude : $altitude m"
  77.         }
  78.         else {
  79.             $altitudeLabel.Text = "Altitude non trouvée"
  80.         }
  81.  
  82.         # Extraction de la longitude à partir de l'URL
  83.         if ($webBrowser.Url.AbsoluteUri -match '/@([0-9.-]+),([0-9.-]+),') {
  84.             $longitude = $matches[2]
  85.             $longitudeLabel.Text = "Longitude : $longitude"
  86.         $global:defaultLongitude = $longitude
  87.         }
  88.         else {
  89.             $longitudeLabel.Text = "Longitude non trouvée"
  90.         }
  91.  
  92.         # Extraction de la latitude à partir de l'URL
  93.         if ($webBrowser.Url.AbsoluteUri -match '/@([0-9.-]+),([0-9.-]+),') {
  94.             $latitude = $matches[1]
  95.             $latitudeLabel.Text = "Latitude : $latitude"
  96.         $global:defaultLatitude = $latitude
  97.         }
  98.         else {
  99.             $latitudeLabel.Text = "Latitude non trouvée"
  100.         }
  101.     }
  102. })
  103.  
  104. $form.Controls.Add($searchBox)
  105. $form.Controls.Add($searchButton)
  106. $form.Controls.Add($returnToStreetViewButton)
  107. $form.Controls.Add($altitudeLabel)
  108. $form.Controls.Add($latitudeLabel)
  109. $form.Controls.Add($longitudeLabel)
  110. $form.Controls.Add($webBrowser)
  111. $form.WindowState = 'Maximized'
  112. [void] $form.ShowDialog()
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement