Click here to Skip to main content
13,351,239 members (53,030 online)

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:

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:

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


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 The Code Project Open License (CPOL).

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100