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="http://earth.google.com/kml/2.0"> <NetworkLink> <description>photos, updates once you stop moving the map.</description> <name>Panoramio</name> <Link> <href>http://www.panoramio.com/kml.php</href> <viewRefreshMode>onStop</viewRefreshMode> <viewRefreshTime>1</viewRefreshTime> </Link> </NetworkLink> </kml>
This network link retrieves KML through a PHP script hosted at panoramio.com. Since this network link has a
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:
kml.phpfile 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: