I've got quite strange google earth plugin behaviour. I get the camera position from the plugin to create some KML with coordinates, then I store it in database. When I reload the page, then it reads the kml, inserts it inside some other string - as a result I've got a string with whole kml document inside my javascript code. Then I load it into the plugin. Usually everything works, however after loading I see two things:
- The coordinates returned by the API are not the same I have in the kml I'm loading
- The camera position is sometimes moved a little bit, which causes errors like: I've got a camera inside a building, and after a couple of page refreshing, the camera suddenly is outside the building.
Do you have any hints how this could be fixed?
Example:
I've created a document, and inserted this camera tag inside:
<Camera>
<gx:ViewerOptions><gx:option name='streetview'></gx:option></gx:ViewerOptions>
<longitude>2.1201209999999993</longitude>
<latitude>48.80452499999986</latitude>
<altitude>2.4999999991174264</altitude>
<heading>22.795249807940547</heading>
<tilt>82.25987544961218</tilt>
<altitudeMode>relativeToGround</altitudeMode>
</Camera>
Then I loaded it into the plugin, and asked to fly there. When it stopeed flying, I got the coordinates using copyAsCamera() and the latitude was changed to 48.8044078508718
.
The difference is not huge, just 0.000117149
but as a result it is showing a totally different place (a different room in the palace.
I'm trying to get exactly the same place, as written in the coordinates.
I have rewritten the answer to cover the various points you have made and the example you have provided.
street view
The KML data is setting
<gx:ViewerOptions>
to enter street view mode based on the camera. The key words being based on - a street view is an approximation. Things like the cameratilt
andheading
are no longer applicable as they are replaced by a SteeetView POV object. Further to that you can't guarantee that a camera at any given latitude and longitude will actually enter street view at the same given latitude and longitude.relativeToGround and terrain data
Using altitude mode
relativeToGround
can cause the issue you are seeing. This is because the terrain data hasn't always finished streaming when the relatively positioned element (in your case a camera) is added.To be clear you should use
<altitudeMode>absolute</altitudeMode>
andge.ALTITUDE_ABSOLUTE
.The example you provided uses both
<altitudeMode>relativeToGround</altitudeMode>
andge.ALTITUDE_RELATIVE_TO_GROUND
.You could also try disabling the terrain data by turning off the terrain layer, i.e.
multiple viewchangeend events
The
viewchangeend
event may fire in the middle of aviewchange
, especially if the plugin pauses for a brief period during the change. Your markup is triggering street view mode which causes this to happen.You can resolve this by using
setTimeout
to throttle theviewchangeend
event like so.see: https://developers.google.com/earth/documentation/events#event_listeners
Tilt discrepancy
The plugin automatically "swoops" at ground level so that it moves from looking straight down (0 degrees tilt) to straight along the horizon (90 degrees tilt). This is what is causing the discrepancy in the tilt value in the view. You are viewing objects at ground level and so the view is being automatically set - this can't be disabled.
Storing and outputting KML data
Take a look through this document, it gives some really good information of storing coordinate data and covers points like the one I mentioned - A Database Driven Earth App.
.