使用 geoxml3 类和 ProjectedOverlay 类将 kml 文件传递​​到 Google 地球时出现问题

发布于 2024-10-08 05:09:05 字数 1726 浏览 7 评论 0原文

我正在尝试构建一个显示城市的谷歌地球视图,但我坚持使用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();

在我的脚本文件中,我声明了 vars,包括

var gm //for google map
var ge //for google earth

gm 在构建谷歌地图的函数中设置。

我想知道如何解决这个问题。我尝试了在网络上找到的 getProjection() 方法,但

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

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

我忘记了什么或做错了什么?

i am trying to build a google earth view showing cities, but i stuck with the kml parser geoxml3. I have a javascript building a google map at first showing the locations i want. this works fine. I call the function from a php script providing it an address and kml file reference from database. The function builds the map, sets a flag 'map_finished' as a control flag when all ran fine and calls the build google earth view function.

// 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 );
}

The geoxml parser uses the ProjectedOverlay class. Both libraries are loaded into document head. When the parser is getting instatiated it requests a ProjectedOverlay instance. This class throws a

Error: **google.maps is undefined**

error in firebug for the following statement

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

In my script file i have declared vars including

var gm //for google map
var ge //for google earth

gm is set in the function that builds the google map.

I wonder how to fix this issue. I tried the getProjection() thing i found in web as well as

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

with no success. This topic is absolutely new to me and i cannot figure out how to fix it neither from the documentation of OverlayView nor from google search.

What did i forget or do wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对不⑦ 2024-10-15 05:09:05

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

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

The call to the geoXML3 constructor is wrong, you must pass the google.maps object as a parameter (...hence the "google.maps is undefined" error).

this.kmlParser = new geoXML3.parser({map: gm}); // gm for google map
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文