【问题标题】:Google map in iframe not centering on the label/markeriframe 中的 Google 地图未以标签/标记为中心
【发布时间】:2011-06-03 13:37:16
【问题描述】:

我一直在尝试使用 iframe 嵌入 Google 地图。但问题是它没有以标签/标记为中心,而是将标记放在左上角(不可见)。

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.in/maps?f=q&source=s_q&hl=en&geocode=&z=8&q=Chennai&output=embed"/>

需要注意的是,当我将其粘贴到 html 文件中时,它工作正常。但在我的情况下,地图的实现就像使用 javascript 的下拉菜单一样。(见下文) 我什至尝试了here 给出的解决方案,但没有结果。

http://prntscr.com/1ziry(这里的标签其实在左上角但没看到)

请帮忙!

【问题讨论】:

  • 对不起。我只是投票给他们。完成!
  • 你能分享更多你的代码吗?

标签: javascript ruby-on-rails google-maps iframe


【解决方案1】:

您为什么要为此使用 iframe。我的猜测是,有一些 JS 魔法可以定位标记并且有一个 iframe 会搞砸它。

使用 Javascript API,您不会有任何问题。 http://code.google.com/apis/maps/documentation/javascript/tutorial.html

【讨论】:

  • 我使用 iframe 是因为它更简单,这是当您点击谷歌地图页面右上角的“链接”时谷歌提供的代码。无论如何,谢谢!
【解决方案2】:

对我来说,问题是加载地图时 iframe 的大小为 0。我添加了延迟来加载地图 iframe 加载之后。

这是我添加到脚本中的代码。 (它作为作为 iframe 加载的 HTML 的一部分运行):

<script>
  window.onload=function(){loadMapDelayed();}

  // delay map display by 100 milliseconds until iframe renders
  function loadMapDelayed() {
    setTimeout("loadMap()",100);
  }
  function loadMap() {
    // existing code that loads the map
  }
</script>

(感谢https://groups.google.com/forum/#!topic/google-maps-api/nN0y2pSr2dQ

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    相关资源
    最近更新 更多