Click here to Skip to main content
15,891,821 members

Converting Delphi code to C# (Getting Google earth coordinates from mouse cursor - Code included)

M.S.S.E asked:

Open original thread
Hi all,

I'm develpoing a small tool using google COM API (I know it's obsolete somehow but it works though)and one of the tasks it does it's to get coordinates from a specific point.
I'm using this method:
//////////////////////////////////
C#
GetPointOnTerrainFromScreenCoords(0,0)


Info about the method:
This method allows an external application to query the geolocation and terrain altitude of a point in the 3D viewpoint identified by its normalized screen coordinates (screen_x, screen_y), ranging from (-1, -1) to (+1, +1) inclusive.
Here are some examples:

(-1, -1) - bottom left hand corner of the screen.
(0,0) - center of the screen.
(1, 1) - top right hand corner of the screen.
//////////////////////////////////

to get the coordinates of the center screen but what I need is to get the coordinates based on the mouse cursor, I've spent much time searching to get the code in C# but I haven't found anything but this delphi code:

Delphi
+LButton::
GE := ComObjCreate("GoogleEarth.ApplicationGE")
CoordMode, Mouse, Relative

    Sleep, 100
    MouseGetPos,MouseX ,MouseY , WhichWindow, WhichControl
    ControlGetPos, RendX, RendY, RendW, RendH, %WhichControl%, ahk_id %WhichWindow%
	ParamX :=  (((2*(MouseX - RendX)) / RendW ) - 1)
	ParamY := -(((2*(MouseY - RendY)) / RendH ) - 1)
	CursPos := GE.GetPointOnTerrainFromScreenCoords(ParamX,ParamY)
    CursLat  := CursPos.Latitude 
    CursLong :=	CursPos.Longitude
	CursAlt  := CursPos.Altitude
	clipboard := Curslat . "," . CursLong . "," . CursAlt
    msgbox, CursLat %CursLat%`nCursLong %CursLong%`nCursAlt %CursAlt%



So what I need now is to convert this block into C# so that I can use it knoing that I havent foung any working converting tool..

Much Thanks.
Tags: C#, Delphi, Google Earth

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900