I am having problems into getting the position (lat/lon) when I click on the globe.
Everywhere on SO (and other websites) suggests to use the getCurrentPosition method.
Unfortunately, this returns the position of the top pickable object which comprehend the point clicked, thus if no pickable object is present there, the method just returns null
You can see it when into the status bar when you use any example: there is every now and then the Off Globe label (instead of lat/lon) even if the mouse is in the globe for this very reason!
Is there any other way to obtain the position without depending on pickable objects? I was thinking about calculating through position on the screen and using geometry, but this would be very much hard and I wouldn't know where to begin...
I'm not sure to which
getCurrentPosition()
you are referring, butWorldWindow#getCurrentPosition()
should do what you want. The javadocs say:If your cursor does not intersect with the globe (i.e. you click on the stars in the background), there is not going to be a position associated with the click. This does not rely on pickable objects, just on the globe intersecting the cursor at the time of the click.
The following example works for me:
If
getCurrentPosition()
is not working for you this is an alternative: