Click here to Skip to main content
12,504,695 members (64,256 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Delphi Google-Earth
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:
//////////////////////////////////
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:

+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.
Posted 20-Jan-13 3:23am
M.S.S.E401
Updated 20-Jan-13 5:39am
v4
Comments
Sergey Alexandrovich Kryukov 20-Jan-13 14:03pm
   
It does not look like a well-formed Delphi Pascal code. Did you loose something during formatting.
Also, this is not quite a valid question, but rather a suggestion to make some of your work. If you had some question on the principles, it would be a different story...
—SA
M.S.S.E 22-Jan-13 5:45am
   
About the Delphi code, I post it as I found it from the source:
http://www.autohotkey.com/board/topic/78127-google-earth-lat-long-under-cursor-hiding-the-ge-cursor/

Cached version:
https://webcache.googleusercontent.com/search?q=cache:Q_PAgZl3zsAJ:www.autohotkey.com/board/topic/78127-google-earth-lat-long-under-cursor-hiding-the-ge-cursor/+&cd=1&hl=en&ct=clnk

the post owner (ymg) has solved the problem I'm facing but in Delphi!, which I'm not good it at all.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Your window must subscribe to a mouse event, e.g. MouseClick, MouseDown, or MouseMove. The EventArgs of that event will tell you the mouse coordinates - already relative to your window, not to the screen as with the Delphi function. Hence there's no need to substract the position (RendX, RendY) of the window; RendW and RendH can be replaced by the ClientRectangle.Width and ClientRectangle.Height properties of your window.
  Permalink  
Comments
M.S.S.E 22-Jan-13 5:03am
   
Hi,
Actually I've tried many times using what you mentioned but non worked, maybe you didn't get what I'm trying to do because I didn't explained well.
What I need is the real coordinates not the form.
please take a look on this example maybe you get what I need to do:

http://www.codeproject.com/Articles/31603/Embedding-Google-Earth-in-a-C-Application

You can import the google earth reference from the binary:

C:\Program Files (x86)\Google\Google Earth\googleearth.exe


Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160919.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2016
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