سؤال

I have written a KML file that I want to embed in order to create a 3D map online. I have been able to successfully use the Google Earth Plug in to text the file and embed it into Blogger and I have validated my code. However, when I try to use the plug in and embed the code into my website, it doesn't work. I have hosted the kml file on my server, which also hosts site that I want to post the map onto. (So, the KML file isn't coming from a computer but is hosted on a server).

Because the Google Plug in isn't working to embed the file, I am trying to figure out why. I have followed the instructions according to the KML developer guidelines and added the functions (see below)

<script>
<html>
  <head>
    <script src="https://www.google.com/jsapi?key=YOURAPIKEY"></script>
    <script>
      google.load('earth','1', {'other_params':'sensor=false'});

      var ge = null;

      function init() {
        google.earth.createInstance('map3d', initCallback, failureCallback);
      }

      function initCallback(pluginInstance) {
        ge = pluginInstance;
        ge.getWindow().setVisibility(true);
      }

      function failureCallback() {
        // we can do something here if there's an error
      }
    </script>

  </head>
  <body onload="init()" id="body">
    <div id="map3d" style="width: 500px; height: 500px;"></div>
  </body>
</html>

However, I am not sure what I am missing. In order for the Google API to work, is there more Javascript that needs to be added to the kml to work? I believe I need to perfect the kml, including code to fetchkml, but I have hit a dead end with the code. I have read many questions on the Google Earth API and kml and cannot find a clear answer to why this works on Blogger but not on my site. I have permissions on my site so that is a non-issue.

A few Stackoverflow questions that have helped but not clearly answered my questions:

Google Earth API, KML on local Web Server

Google earth fetchKml timeout

Any assistance in helping me integrate my kml with the Google Earth API and javascript is appreciated.

هل كانت مفيدة؟

المحلول

The code looks AOK apart from the line

<script src="https://www.google.com/jsapi?key=YOURAPIKEY"></script>

Really it should either have your api key in the query, or else simply be

<script src="https://www.google.com/jsapi"></script>

As it is, it could be that you are simply getting an invalid API key error.

If that doesn't solve it could you post a link to your actual site where it isn't working?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top