简体   繁体   中英

how to add dynamic kml to google earth?

We are trying to add dynamic kml to google earth.But we are failing in one situation.

CODE:

var currentKmlObject = null;
function loadkmlGE(){
     if (currentKmlObject != null) {
            ge.getFeatures().removeChild(currentKmlObject);
            currentKmlObject = null;
          }

    var url = 'test.kml';
    google.earth.fetchKml(ge, url, finished);
    }

function finished(kmlObject) {
      if (kmlObject) {
        currentKmlObject = kmlObject;
        ge.getFeatures().appendChild(currentKmlObject);
      } else {
        setTimeout(function() {
          alert('Bad or null KML.');
        }, 0);
      }
    }

When we click on button we are calling loadkmlGE() function.We are able to get the kml first time on google earth.If we click second time then we are not getting kml on google earth.But test.kml file is updating new values.So, how we can remove the kml from google earth?

Help would be appreciated.

fetchKml I beleive uses the browser to fetch the file. It will generally cache the file unless told otherwise.

You could arrange for the server to tell the browser it cant cache the file - using HTTP headers. depends on your server how to set that up.

... or just arrange the url to change each time.

var url = 'test.kml?rnd='+Math.random();

or similar. The server will likly ignore the bogus param. But as the URL has changed the browser wont have a cached version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM