Google AJAX API 入门笔记(一)

1.首先,从Google网站注册一个相关Google AJAX API密钥;

2.使用 Google 地球 API 要在网页中载入 Google 地球插件,您需要进行以下操作:

  I.载入 Google 地球 API[用相关密钥来替换以下内容中的ABCDEFG部分]。

<script src="http://www.google.com/jsapi?key=ABCDEF"></script>

  II.创建 DIV 元素来包含该插件。

<div id="map" style=" 800px; height: 600px;" />

  III.创建初始化插件的函数。

代码
  var ge;
  google.load("earth", "1");
  function init() {
     google.earth.createInstance("map", initCallback, initFailure);
  }
  function initCallback(instance) {
     ge = instance;
     ge.getWindow().setVisibility(true);
  }
  function initFailure(errorCode) {
  }
 
 IV.网页载入后,调用该初始化函数。
google.setOnLoadCallback(init);

  V.完整代码:

 
代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    
<title>Google Earth</title>
    
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
    
<script src="http://www.google.com/jsapi?key=ABCDEFG"></script>
    
<script language="javascript" type="text/javascript">
    
// <![CDATA[

        var ge;
        google.load(
"earth""1");

        function init() {
            google.earth.createInstance(
"map", initCallback, initFailure);
        }

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

        function initFailure(errorCode) {
        }

        google.setOnLoadCallback(init);

    
// ]]>
    </script>
</head>
<body>
    
<div id="map" style=" 800px; height: 600px;">
    
</div>
</body>
</html>
原文地址:https://www.cnblogs.com/gaotang/p/1771582.html