Stay organized with collections
Save and categorize content based on your preferences.
By default, data is loaded only once by Links into Google Earth. To prevent KML data from becoming stale, you can specify a refreshMode of onExpire for any data loaded by an <href> element (in a Link or Icon element). By default, HTTP expiration headers specify the expiration time. You can also now specify an expires time in a KML NetworkLinkControl. The time is expressed as an XML dateTime (see XML Schema Part 2: Datatypes Second Edition). If both HTTP headers and KML expiration times are specified, the KML expiration time takes precedence.
Example 1: Expiration using HTTP server expiration time
This example is for illustration only. It shows a GroundOverlay with an Icon that sets a refreshMode of onExpire. Since no KML expiration time is set, this example uses the HTTP server expiration time.
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <name>refreshMode onExpire</name> <Snippet maxLines="10"> Image automatically reloads according to http server expiration. </Snippet> <GroundOverlay> <Icon> <href>http://www.someserver.com/image.jpeg</href> <refreshMode>onExpire</refreshMode> </Icon> <LatLonBox> <!-- from edit session in earth --> <!-- The roof of a building in the Presidio --> <north>37.80385180177469</north> <east>-122.4558710620651</east> <south>37.80337403503347</south> <west>-122.4564295653771</west> </LatLonBox> </GroundOverlay> </Document> </kml>
Example 2: Example using KML expiration time
The following example delivers a Placemark at randomly selected coordinates. This example includes a Link with a refreshMode of onExpire. In this case, the expiration date/time is specified (in a Python script) using the new KML <expires> element. This KML expiration time takes precedence over any time that may have been specified in the HTTP headers.
Here is the KML NetworkLink containing the Link with the <href> and <refreshMode> elements:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-11-03 UTC."],[[["\u003cp\u003eBy default, Google Earth loads data only once, but you can refresh KML data using the \u003ccode\u003erefreshMode\u003c/code\u003e tag set to \u003ccode\u003eonExpire\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eExpiration times can be set using HTTP headers or the KML \u003ccode\u003e<expires>\u003c/code\u003e element within a \u003ccode\u003e<NetworkLinkControl>\u003c/code\u003e, with the KML element taking precedence.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003e<expires>\u003c/code\u003e element utilizes the XML dateTime format to specify the refresh time.\u003c/p\u003e\n"],["\u003cp\u003eTwo examples demonstrate refreshing data based on HTTP server expiration and a specific KML-defined expiration time, respectively, using \u003ccode\u003e<href>\u003c/code\u003e and \u003ccode\u003e<refreshMode>\u003c/code\u003e within a \u003ccode\u003e<Link>\u003c/code\u003e element.\u003c/p\u003e\n"]]],[],null,["By default, data is loaded only once by Links into Google Earth. To prevent KML data from becoming stale, you can specify a *refreshMode* of *onExpire* for any data loaded by an \\\u003chref\\\u003e element (in a Link or Icon element). By default, HTTP expiration headers specify the expiration time. You can also now specify an *expires* time in a KML NetworkLinkControl. The time is expressed as an XML dateTime (see [XML Schema Part 2: Datatypes Second Edition](http://www.w3.org/TR/xmlschema-2/#dateTime)). If both HTTP headers and KML expiration times are specified, the KML expiration time takes precedence.\n\nExample 1: Expiration using HTTP server expiration time\n\nThis example is for illustration only. It shows a GroundOverlay with an Icon that sets a *refreshMode* of *onExpire*. Since no KML expiration time is set, this example uses the HTTP server expiration time. \n\n```\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ckml xmlns=\"http://www.opengis.net/kml/2.2\"\u003e\n\u003cDocument\u003e\n \u003cname\u003erefreshMode onExpire\u003c/name\u003e\n \u003cSnippet maxLines=\"10\"\u003e\n Image automatically reloads according to http\n server expiration.\n \u003c/Snippet\u003e\n \u003cGroundOverlay\u003e\n \u003cIcon\u003e\n \u003chref\u003ehttp://www.someserver.com/image.jpeg\u003c/href\u003e\n \u003crefreshMode\u003eonExpire\u003c/refreshMode\u003e\n \u003c/Icon\u003e\n \u003cLatLonBox\u003e\n \u003c!-- from edit session in earth --\u003e\n \u003c!-- The roof of a building in the Presidio --\u003e\n \u003cnorth\u003e37.80385180177469\u003c/north\u003e\n \u003ceast\u003e-122.4558710620651\u003c/east\u003e\n \u003csouth\u003e37.80337403503347\u003c/south\u003e\n \u003cwest\u003e-122.4564295653771\u003c/west\u003e\n \u003c/LatLonBox\u003e\n \u003c/GroundOverlay\u003e\n\u003c/Document\u003e\n\u003c/kml\u003e\n```\n\nExample 2: Example using KML expiration time\n\nThe following example delivers a Placemark at randomly selected coordinates. This example includes a Link with a *refreshMode* of *onExpire*. In this case, the expiration date/time is specified (in a Python script) using the new KML \\\u003cexpires\\\u003e element. This KML expiration time takes precedence over any time that may have been specified in the HTTP headers.\n\nHere is the KML NetworkLink containing the Link with the \\\u003chref\\\u003e and \\\u003crefreshMode\\\u003e elements: \n\n```\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ckml xmlns=\"http://www.opengis.net/kml/2.2\"\u003e\n\u003cDocument\u003e\n \u003cNetworkLink\u003e\n \u003cLink\u003e\n \u003chref\u003ehttp://dev.someserver.com/cgi-bin/expires.py\u003c/href\u003e\n \u003crefreshMode\u003eonExpire\u003c/refreshMode\u003e\n \u003c/Link\u003e\n \u003c/NetworkLink\u003e\n\u003c/Document\u003e\n\u003c/kml\u003e\n```\n\nThis is the Python script that sets an expires time of \\[*now* + 11 seconds\\] and refreshes the Placemark's coordinates: \n\n```\n#!/usr/bin/python\n\nimport random\nimport time\n\nlat = random.random() * 180. - 90.\nlon = random.random() * 360. - 180.\n\nnow = time.time()\nfuture = time.gmtime(now + 11)\ny = future[0]\nmo = future[1]\nd = future[2]\nh = future[3]\nmi = future[4]\ns = future[5]\niso8601 = '%04d-%02d-%02dT%02d:%02d:%02dZ' % (y,mo,d,h,mi,s)\n\nprint 'Content-type: application/vnd.google-earth.kml+xml'\nprint\n\nprint '\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e'\nprint '\u003ckml xmlns=\\\"http://www.opengis.net/kml/2.2\\\"\u003e'\n\n# must be child of \u003ckml\u003e\nprint '\u003cNetworkLinkControl\u003e'\nprint '\u003cexpires\u003e%s\u003c/expires\u003e' % iso8601\nprint '\u003c/NetworkLinkControl\u003e'\n\nprint '\u003cPlacemark\u003e'\nprint '\u003cname\u003eplacemark expires %s\u003c/name\u003e' % iso8601\nprint '\u003cPoint\u003e'\nprint '\u003ccoordinates\u003e%f,%f,0\u003c/coordinates\u003e' % (lon,lat)\nprint '\u003c/Point\u003e'\nprint '\u003c/Placemark\u003e'\n\nprint '\u003c/kml\u003e'\n```\n\n[Back to top](#top)"]]