Better KML Support in Maps API (Dynamic Streaming Markers, Oh my!)

Tuesday, October 16, 2007 at 3:05:00 PM

Maps has just added support for view and interval based refresh in KML Network Links. This means that NetworkLinks can now provide you with dynamic, living content. You can, for instance, refresh marker locations every few seconds, or load only the geometry contained within the current viewport. This reduces load on your server and the browser, and provides for a richer experience for the user. These types of network links have worked in Google Earth for quite a while now, but this is the first time that they're working in Maps, and in the Maps API using GGeoXml.

OK, enough said, let's see some code. The following is an example of a NetworkLink that uses view based refresh:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="">
        <description>photos, updates once you stop moving the map.</description>

This network link retrieves KML through a PHP script hosted at Since this network link has a viewRefreshMode of onStop, it will automatically append a bounding box parameter to the end of the URL - BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth] - with the bracketed parameters replaced by values that describes the current map viewport. So, one second after the user stops panning or zooming the map, the NetworkLink might call a URL like this:,-10,10,10
Then the kml.php file looks at the BBOX parameter value sent in and sends back a KML document that only contains the placemarks visible inside that bounding box. The end result, when embedded on a Maps API map, looks something like this:

If you want more information on view based refresh, check out the KML Reference. If you want more information on using KML in the Google Maps API, check out the Maps API documentation.