Tuesday, October 26, 2010

KML in Google Maps API

There are various ways of loading layers over google maps. One way is creating spatial objects and loading it from within the Java Script. If you you do not wish to touch the Java script code an alternative is using KML (Keyhole Markup language) file. Its basically in XML format and some things need to be taken into consideration when writing one, as a single silly mistake can get on your nerves. In this example i have drawn a polygon across a small area.

Below is what you will have in your html :

Object gx holds this KML file . You just have to add it as an overlay. Remember, your kml files have to on some public server and not localhost.
The content of KML is as follows :

In The KML file, the first thing that should be taken care of is namespace or xmlns="http://www.opengis.net/kml/2.2" which, if is wrong, Google won't load that kml. Each object can be displayed using Placemark which has a name and the object definition (Polygon in my case). Additionally you can add markers, polyline etc.

No comments:

Post a Comment