Search code examples
google-earth-plugin

Obtaining GE Plugin Client Coordinates


I am writing a WinForms application with a WebBrowser control. I use Google Earth Plugin in this application, and need to create some placemarks on Google Earth. Depending on the current range (zoom level) some of the placemarks may be very close to each other on screen (when the earth is zoomed out enough). In this case I want to create not all but just some of the placemarks to avoid over-crowding the map on screen with placemarks.

For example, suppose I have 1000 points I want to create placemarks. When I loop through all the points for the placemarks to be created I want to convert the lat/long of each point to the WebBrowser control's client coordinates so I can check to see if it is very close (on screen) to other placemarks already created. If it is very close to other placemarks I just skip the creation of this one. So if the user zoomed out to a certain degree the actual number of placemarks created may be much smaller than 1000 (for example, 400).

This is where I have difficulty with. I don't know if there is a way to convert lat/long to client coordinates of the WebBrowser control hosting Google Earth Plugin. I know that for mouse events the client coordinates are there for me to use but there is no mouse event involved in this case.

Anybody has an idea how this can be achieved? Thanks!


Solution

  • The approach you're trying to use to fix the problem is incorrect. However there a few options:

    Going with your current approach -- you have two options:

    1. You can ask the current view to convert a given lat/lon to screen X/Y.

      https://developers.google.com/earth/documentation/reference/interface_g_e_view#a8c39d0324f2350c54fe2de981f1be418

    2. You can get client mouse coordinates as part of KML mouse events that are fired off the GEWindow class:

      https://developers.google.com/earth/documentation/reference/interface_g_e_window-members

      The KMLMouseEvent that is fired contains client X/Y space:

      https://developers.google.com/earth/documentation/reference/interface_kml_mouse_event

    The correct approach would be to add KML region tags to your placemarks so that placmarks show/hide as the user pans/zooms etc.

    http://www.google.com/earth/outreach/tutorials/region.html