使用geoxml3类和ProjectedOverlay类将kml文件传递到Google Earth的问题

时间:2010-12-15 12:50:18

标签: google-maps kml google-earth-plugin

我正在尝试建立一个显示城市的谷歌地球视图,但我坚持使用kml解析器geoxml3。我有一个javascript构建一个谷歌地图,首先显示我想要的位置。这很好用。我从php脚本调用该函数,为其提供数据库中的地址和kml文件引用。该函数构建地图,当所有运行正常并调用构建谷歌地球视图功能时,将标志“map_finished”设置为控制标志。

// Get maps and earth from google
google.load( 'maps', '2.s', {'other_params': 'sensor=true'} );
google.load( 'earth', '1' );

//Google Earth Initializer
function initObjectEarth() {
  // Check if Google Earth plugin is installed   
  if( gm_loaded ) {
  this.ge_plugin_installed = google.earth.isInstalled();

  if( this.ge_plugin_installed ) {
    google.earth.createInstance( 'inmap', geSuccessCallback, geFailureCallback );
    ge_loaded = true;
  } else {
    alert( 'Your Browser has not yet installed the Google Earth plugin. 
            We recommend installing it to use all features!' );
    return false;
  }
 }
}

// Success handler
function geSuccessCallback( object ) {
  this.ge = object;
  this.ge.getWindow().setVisibility( true );
  this.kmlParser = new geoXML3.parser();
}

// Error handler
function geFailureCallback( object ) {
   alert( 'Error: ' + object );
}

geoxml解析器使用ProjectedOverlay类。两个库都加载到文档头中。当解析器获得实例化时,它会请求ProjectedOverlay实例。这个类抛出一个

Error: **google.maps is undefined**
firebug中的

错误以下声明

ProjectedOverlay.prototype = new google.maps.OverlayView();

在我的脚本文件中,我已声明包含

的变量
var gm //for google map
var ge //for google earth

gm在构建谷歌地图的功能中设置。

我想知道如何解决这个问题。我尝试了在web和

中找到的getProjection()
ProjectedOverlay.prototype = new google.maps.OverlayView().prototype;

没有成功。这个主题对我来说绝对是新的,我无法弄清楚如何从OverlayView的文档或谷歌搜索中解决它。

我忘了或做错了什么?

1 个答案:

答案 0 :(得分:0)

对geoXML3构造函数的调用是错误的,您必须将google.maps对象作为参数传递(...因此“google.maps未定义”错误)。

this.kmlParser = new geoXML3.parser({map: gm}); // gm for google map
相关问题