Grabbing Latitude / Longitude out of a KML file

1,842 views
Skip to first unread message

The_Wind_777

unread,
May 4, 2006, 11:41:17 AM5/4/06
to KML Discussions
This is probably a stupid question, and probably has to do with 3D Math, but... here goes.


I am currently using AccessBasic to read in, grab placemark names, then write out the Latitude and Longitude of each placemark.

However, I found that when you just grab the Latitude and Longitude out of the file, they aren't correct.

If you put those latitude / longitude coordinates back into GoogleEarth, then you don't get the exact same spot on the globe?

And, if I do an extremely close rollover on a placemark, the Pointer Lat and Lon don't match up.

I'm wishing to use decimal mode.

Let's give an example...

I put a placemark in the very center of Sedan Crater at the Nevada Test Site

I zoom in the interface until I can't zoom in any more, roll over so I'm exactly centered on the placemark crosshairs and the rollover coordinates say:

Pointer Lat 37.176961 Lon -116.046097 elev 4032 ft.

I write out a KML file and inside, it says this:

<Placemark>
<name>(Nothing to do with bike trip) Nevada Test Site - Sedan Explosion</name>
<LookAt id="khLookAt737">
<longitude>-116.0469812505719</longitude>
<latitude>37.17686224286457</latitude>
<range>1014.685426290953</range>
<tilt>-1.129373905529457e-011</tilt>
<heading>-0.1400624146646101</heading>
</LookAt>
<styleUrl>root://styleMaps#default+nicon=0x307+hicon=0x317</styleUrl>
<Style id="khStyle738">
<IconStyle id="khIconStyle739">
<Icon>
<href>root://icons/palette-3.png</href>
<x>96</x>
<y>96</y>
<w>32</w>
<h>32</h>
</Icon>
</IconStyle>
</Style>
<Point id="khPoint745">
<coordinates>-116.0460964057671,37.17696087000618,0</coordinates>
</Point>
</Placemark>

If I then grab the latitude and longitude from that:

37.17686224286457, -116.0469812505719

Immediately, you can see that the two don't match.

The rollover said:

37.176961, -116.046097

and, if you round that off, you get:

37.176862, -116.046981

So, particularly with the Longitude, it's quite badly off.

If you put the coordinates from the KML file back into Google Earth and push ENTER, you will get a placemark that's shifted to the left of where it should be by about a seventh the width of Sedan Crater.

...

However, if you look at the values between <coordinates> and </coordinates>, those seem to be the right values.

So, how does one convert the <latitude> <longitude> values so they equal the <coordinate> values?

And sometimes it's even much worse than that. Sometimes it will shift many inches between the reading it gives you by rolling over the interface, and the coordinates you take from the KML file.

Somehow, I want to be able to have an equation that I use to put the KML Latitude / Longitude values through so I can use them to put back into Google Earth arrive exactly at the proper placemark position, where it should be.

Is there some sort of mathematical computation that's going on, having to do with the range, tilt and heading values not being exactly perfect to make the two match up properly?

barryhunter

unread,
May 4, 2006, 12:27:05 PM5/4/06
to KML Discussions
just use the <coordinates> ... </coordinates> value, that is the exact position of the placemark.

the position inside the <longitude> and <latitude> are actually inside a <LookAt> tag, which means that its specifying the center of the screen, which depending on the exact viewpoint can be quite different to the placemark position, like you apparently found.

basically as long as the Lookat values are basically right, doesn't matter what they are, if you want you can rewrite them to be the same as the <coordinates> tag, GE will might end up moving them slightly so that it can make the view sensible

Does that help?

The_Wind_777

unread,
May 4, 2006, 2:22:53 PM5/4/06
to KML Discussions
By the way, just so people can understand why I'm doing this... I'm writing a book which is about my first bicycle trip across America, and I've gotten every place that we went placemarked with Google Earth.

I'll be including Latitude / Longitude values in my book so people with GPS units will be able to go to any exact place that we did.

If I change any of the placemarks in Google Earth, I need to spit out a new listing of all the placemark Latitude / Longitude and Elevations.
408697-MyPlaces_Everything.zip

The_Wind_777

unread,
May 4, 2006, 3:01:10 PM5/4/06
to KML Discussions
Yeah, I kind of figured out half-way through posting that the <coordinates></coordinates> values were correct and so I rewrote it to use those, instead.

Now, my question is is there anyway to be able to get the Elevation value that shows next to the Latitude and Longitude when you have Terrain turned on from the KML file?

I tend to doubt it, but just thought I'd ask. At the moment, I tack on a hyphen onto the end of the Placemark's name, and then put the elevation after the hyphen

( Like Sedan Crater - 1036 ft )

Then, I grab whatever's after the last hyphen (if any) on a placemark name line and use that when I'm saying what the elevation is.

It would be nicer if I didn't have to manually put the elevation into the placemark's name, though. Not only do I have to always zoom in to the fullest extent so it will be accurate, but I have to then read the value while centering the placemark, write it down, then do an edit, and it's annoying to have to do all of that.

It would be far easier if I could grab the terrain elevation for a placemark from the KML file.

tekgergedan

unread,
May 5, 2006, 4:10:48 AM5/5/06
to KML Discussions
Altitude is the third parameters in each coordinate which possibly is now "0" in your kml.

For an easy script for this, the answer is in barry's link in his signature.

Calico_Jack

unread,
May 5, 2006, 1:42:30 PM5/5/06
to KML Discussions
Quote:

By the way, just so people can understand why I'm doing this... I'm writing a book which is about my first bicycle trip across America, and I've gotten every place that we went placemarked with Google Earth.

I'll be including Latitude / Longitude values in my book so people with GPS units will be able to go to any exact place that we did.

If I change any of the placemarks in Google Earth, I need to spit out a new listing of all the placemark Latitude / Longitude and Elevations.



Pretty interesting bunch of placemarks! I like the notes about foxes and fairy circles and things like that.

I get tired just thinking about riding as far as you did!

You might want to consider organizing your placemarks in chunks. I was trying to play all of them as a a tour but kept getting side tracked.

Congratulations on what looks like a GREAT ride. I'm not a bicyclist, but this makes me want to get in shape and try something monumental.
Reply all
Reply to author
Forward
0 new messages