testtestHome

How to link Google Earth to your photoblog…

11.03.2006 by Mich

Haven’t you ever wanted to map all your pictures on the earth surface? There already are some things like Mappr, but it’s only available in the US and is only for those with Flickr accounts. I myself programmed my own photoblog, which makes it more difficult to use a tool like that, especially when I live in Europe.

While I was saving some points of interest in Google Earth, I noticed they had 2 formats: “.kmz” and “.kml”. Since I was curious, I saved the file in both formats and opened them in an editor. The “.kmz” was just a boring binary file where I could not understand a clue of the special characters, while the “.kml” was an xml-file. I googled for some more information and landed on a tutorial page as well as a general reference.

Since I already linked all my pictures with Google Maps by keeping their longitude and latitude, I was only one step away to generate a file that would point out all my pictures in Google Earth. So there I went: I fetched all the rows out of my database that contained longitude and latitude and iterated over the list to generate all the “Placemark” items.

Basically, this is how my PHP-script generates the “<placemark>” items:

<?
        
echo "<Placemark>";
        echo
"<description><![CDATA[<a href="http://visual.emich.be/?picid=$id">$name<br><img src="http://www.emich.be/images/$dir/tmb$file" alt="$name"/></a><br>$description]]></description>";
        echo
"<name>$name</name>";
        echo
"<LookAt><longitude>$ycoord</longitude>";
        echo
"<latitude>$xcoord</latitude>";
        echo
"<range>540.68</range>";
        echo
"<tilt>0</tilt>";
        echo
"<heading>3</heading>";
        echo
"</LookAt>";
        echo
"<Point>";
        echo
"<coordinates>$ycoord,$xcoord,0</coordinates>";
        echo
"</Point>";
        echo
"<Style><IconStyle><Icon><href>root://icons/palette-4.png</href>
        <x>192</x><y>64</y>
        <w>32</w><h>32</h></Icon></IconStyle></Style>"
;
        echo
"</Placemark>";
?>

The result is different placemarks, like this one:

<Placemark>
    <description>
        <![CDATA[ <a href="http://visual.emich.be/?picid=2">Le bout du tunnel<br><img src="http://www.emich.be/images/misc/tmbbrol140505.JPG" alt="Le bout du tunnel"/></a><br>Et tout en haut, il y a Maria
    ]]>
    </description>
    <name>Le bout du tunnel</name>
    <LookAt>
        <longitude>4.36772222222</longitude>
        <latitude>50.8488722222</latitude>
        <range>540.68</range>
        <tilt>0</tilt>
        <heading>3</heading>
    </LookAt>
    <Point>
        <coordinates>4.36772222222,50.8488722222,0</coordinates>
    </Point>
    <Style>
        <IconStyle>
            <Icon>
                <href>root://icons/palette-4.png</href>
                <x>192</x>
                <y>64</y>
                <w>32</w>
                <h>32</h>
            </Icon>
        </IconStyle>
    </Style>
</Placemark>

Finally, I just have to set the central point of my “globe” in the root "<Document>"-tag. In my case, this would be Brussels, Belgium.

<LookAt>
  <longitude>4.351995</longitude>   <latitude>50.846617</latitude>
  <range>5000</range>
  <tilt>0</tilt>
  <heading>3</heading>
</LookAt>

The result is a .kml-file that can be downloaded at this location and will open in Google Earth, so you can see all the spots of which I have a picture. It displays a little camera at each spot, and the description has a thumbnail. If you click on the thumbnail, you'll arrive on the pages on the photoblog.

I am thinking of writing a script for flickr, that works the same way as mappr, but for Google Earth. Using 2 tags and a specific tag and for latitude/longitude. Maybe even more…

The advantage of generating a KML-file is you don't have to do any maintenance on it!

Anyway, I just wanted to share this with others.

tags: . . . . |
[... old blogs and new, and here are some new ...]
KMZ File par phaZer (13/03/2006 @ 13:29)
Is just a zip file of the KML file.
[... old blogs and new, and here are some new ...]
Leave a comment
  • Your name *

  • Your email *

  • Homepage

  • Your comment *

  • * = required


  • Remember me