Wednesday, 24 September 2008

Displaying KML/KMZ files in Google Maps

KML/KMZ files can be overlaid on Google Maps, either on the Google Maps website, or by using the GGeoXML class of the Google Maps API (see example).

Google Maps

Google Maps API

Google Earth

The KMZ file (download) displayed above was generated by the Thematic Mapping Engine. Only a subset of the KML standard is so far supported by Google Maps. The shaded plygons are properly displayed, but not the screen overlays (title and legend) and balloons. The different placement of the zoom bar in Google Maps and Google Earth makes it difficult to display the same KML/KMZ file in multiple viewers.

I'm impressed by the speed of Google Maps. The above KMZ file contains complex geometries of almost 200 countries of the world. Web browsers are not optimized for vector graphics, as illustrated on this page. To avoid this problem, Google seems to use its powerful servers to generate image map tiles on-the-fly from the KML geometries.

A bug in the map tile generator was discovered when displaying the World Borders dataset in Google Maps:

The polygon representing Russia is not displayed properly. The country is crossing the antimeridian at 180° longitude. To avoid a round trip of the Earth, the eastmost part of Russia is stored as a separate polygon. Russia is not displayed properly because 180° longitude is rendered as 0° longitude (the Prime Meridian). The problem was fixed by replacing all 180 coordinate values width 179.99. I won't correct this in the World Borders dataset, as I consider this to be a bug in Google Maps. If you don't want to change the orginal dataset, you can replace the longitude values when the KML document is generated, or by doing a search/replace in a text editor on the KML document.


Anonymous said...

The problem is in your data. Russia is not split in two along the dateline. It should be one big polygon.

Unknown said...

One or two polygons - there is still a bug in Google Maps as 180° longitude is not rendered properly.