So I have been working on a little side project that involves Google Earth, and I thought I would share my findings with you all in the form of this little tutorial.
One of the most frustrating things about working with Google’s technology is the lack of good, clear documentation. Most of your time is taken up with searchng for answers through a trial and error type of programming.
This tutorial won’t cover all there is to know about Google Earth, but I am confident that after reading this you will be capable of getting down to business and having some serious fun.
Okay, so I wanted to create an add-on for Google Earth that would list all of the sites in the 9rules network, affectionately dubbed 9rules Earth, and I wanted to have a web form component that would allow the members of the network to add thier sites to 9rules Earth, so I wasn’t inputing hundreds of sites.
Sounds simple enough, so let’s get to it.
KML is the powerhouse behind Google Earth; it is a simple, well formed markup language based on XML… so you know right away that this is going to be easier than we thought.
In your KML File you define a ‘placemark’ that corresponds to your house/website/thingy. A typical point would look like this:
<Placemark> <description>This is our house, aint it shiny.</description> <name>Our House</name> <visibility>1</visibility> <Point> <coordinates>76.7142,39.0996,0</coordinates> </Point> </Placemark>
So as you can see here we have set up our first placemark and given it a name: Our House, description: This is our house, aint it shiny, set its visibility to 1:”(0 means the ‘point’ is not visible on the map, 1 means it is.)”: and finally given Google Earth the coordinates so it can find our house:”(Remember longitude first, then latitude.)”: .
Pretty simple right? Right. So lets say we want to add a custom ‘point’ icon to our placemark, say a picture of our house… what then?
Well luckily KML has that covered as well with the Style decleration:
<Style> <IconStyle> <Border id="khBorderDefault"> <width>0</width> <color>ff000000</color> </Border> <Icon> <href>http://www.ourwebsite.com/images/point.png</href> <w>32</w> <h>32</h> </Icon> </IconStyle> </Style>
So lets look at the above code and what it is doing exactly. To add your own custom point image you need to create the Style block and declare your IconStyle; you will notice that I have declared Border with a width of 0. Why not just skip that all together? If you don’t declare Border at all then you get a white background effect that is not cool, so go ahead and just declare it and make it 0.
Next we get to the important part, declaring Icon. Any URI that you reference in KML needs to be bracketed in <href>’s, be fully qualified and have width and height declared.
So let’s put it all together to create a point that has a custom icon:
<Placemark> <description>This is our house, aint it shiny.</description> <name>Our House</name> <visibility>1</visibility> <Style> <IconStyle> <Border id="khBorderDefault"> <width>0</width> <color>ff000000</color> </Border> <Icon> <href>http://www.ourwebsite.com/images/point.png</href> <w>32</w> <h>32</h> </Icon> </IconStyle> </Style> <Point> <coordinates>76.7142,39.0996,0</coordinates> </Point> </Placemark>
Now all we have to do is save this as our-point.kml and open it with Google Earth. You will now be able to find your point at the coordinates you specified, isn’t that shiny?
So that is it for part 1, in Part 2 we will cover more than one Placemark in your KML file, and how to automate the input of sites and creation of the KML file from data stored in a database. Be warned there will be a fair amount of coding going on around this mother in Part 2. Just remember I warned you.
Stroll on over and visit Jim
March 1, 2007
Pretty cool, Chris. Looking forward to part 2!
Stroll on over and visit Mike
March 1, 2007
Wow, so cool man! I can’t wait to see how it all comes out. Fantastic.
Stroll on over and visit Mike
March 1, 2007
Haha what’s up with that weird gravatar for my other comment??
Stroll on over and visit Colin D. Devroe
March 1, 2007
Dude, your podcast, sounds nothing like you. :)
Can’t wait to see the final product.
Stroll on over and visit seer
March 1, 2007
You might enjoy the KML spec at code.google.com, and the KML how-to support forum at bbs.keyhole.com, the official Google Earth Community. (300k members and many more anon readers)
Stroll on over and visit Petit
March 1, 2007
An excellent idea!
Podz is up to for the blogger community, as you can find on his “What makes you happy” blog. It’s a good way of enhancing the social aspects of the web.
For your tutorial, I guess you are aware of the possibilities to avoid too much hand coding of KML files. You want to present your site or house as nicely as possible.
What you can do, is to place your mark and then rotate, zoom and tilt the Google Earth to the position, altitude, direction and angle you wish your visitors to see at arrival. In the placemark editor you then catch this information with one click of the mouse. From within GE you can then save the information as KML, or KMZ, which is the gzipped version. Also within the editor you may introduce the URL for an image to show up on as a placemark instead of the standard pin and you can add any text and link to your site, before you save it.
Here is proudly my spot on the virtual Tellus as an example if you like!
Stroll on over and visit Petit
March 1, 2007
Oops! Something strange happened to my post.
No real links and I cannot find any contact info to Chris.
Stroll on over and visit Hennry
March 1, 2007
Great idea! I love Google Earth and I’ve been thinking of doing this for some time now.
Stroll on over and visit Daniel
March 1, 2007
Hi All Experts,
Does anyone use google earth images as ground image planes for use in aerial scenes. I know how to stitch them together but are there any tools or tricks to make sure that the images are at the same height, angle and such to make sure they stitch well. I know in the pro version you can get bigger images but im not going to pay for the pro version when i could stitch multiple images together…
Pingbacks & Trackbacks
Leave a Reply