【问题标题】:Google maps tour won't work inside an iframe谷歌地图游览在 iframe 中不起作用
【发布时间】:2014-07-24 21:10:32
【问题描述】:

我需要将此导览嵌入到网站:

https://www.google.es/maps/@39.566752,2.649834,3a,75y,113.38h,90t/data=!3m5!1e1!3m3!1s86s2yikaJz6n9Ezi7bJmTw!2e0!3e2

但问题是

<iframe src="https://www.google.es/maps/@39.566752,2.649834,3a,75y,113.38h,90t/data=!3m5!1e1!3m3!1s86s2yikaJz6n9Ezi7bJmTw!2e0!3e2"></iframe>

什么都不显示

有什么建议吗?

【问题讨论】:

  • 新地图似乎不支持嵌入街景,请使用旧地图。
  • 您好,您能解释一下old maps 的意思吗?谢谢!
  • <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.es/maps?cbll=39.566752,2.649834&layer=c&panoid=86s2yikaJz6n9Ezi7bJmTw&cbp=12,113.38,,0,0&ie=UTF8&ll=39.534762,2.690964&spn=0.237775,1.056747&t=m&z=11&source=embed&output=svembed"></iframe>
  • 在新地图的底部,您会发现一个问号。单击它并选择“返回经典地图”。在经典(旧)地图中,使用单击共享按钮时提供的嵌入代码。
  • SO 在代码中放置了一些空格,工作小提琴:jsfiddle.net/doktormolle/7qqpw

标签: html google-maps iframe embed


【解决方案1】:

对于新版本的谷歌地图,为了显示您的地图,您需要通过链接的集成版本,您不能只通过 iframe 内的共享 URL,因为对于经典的谷歌地图来说,这是微不足道的从共享链接转换为 iframe 嵌入 URL,因为它本质上具有相同的 URL 参数,您只需添加一个 output=embed URL 参数,以便 Google 输出嵌入布局而不是桌面站点布局。

所以,我认为你应该使用 Safari 浏览器,因为谷歌地图由于某种原因没有在其中更新。 对于您的情况:您需要处理网址:https://maps.google.es/maps?ll=39.566752,2.649834&spn=0.369997,0.837021&cbll=39.566752,2.649834&layer=c&panoid=86s2yikaJz6n9Ezi7bJmTw&cbp=12,113.38,,0,0&t=m&z=11

这就是我的做法:

$url = $options["url"];
$url = parse_url($url);
$query = array();
parse_str( $url['query'], $query );
$iframe = "<iframe  marginheight=\"0\" marginwidth=\"0\" "; 
$iframe .= "src=\"https://maps.google.com/maps?f=q";    
$iframe .= "&amp;source=s_q";   
$iframe .= "&amp;hl=fr";    
$iframe .= "&amp;geocode="; 
if(isset($query['q'])) $iframe .= "&amp;q=".$query['q'];    
$iframe .= "&amp;aq=";  
if(isset($query['sll'])) $iframe .= "&amp;sll=".$query['sll'];  
if(isset($query['sspn'])) $iframe .= "&amp;sspn=".$query['sspn'];
$iframe .= "&amp;t=m";
$iframe .= "&amp;ie=UTF8";
if(isset($query['hq'])) $iframe .= "&amp;hq=".$query['hq'];
if(isset($query['hnear'])) $iframe .= "&amp;hnear=".$query['hnear'];
if(isset($query['ll'])) $iframe .= "&amp;ll=".$query['ll'];
if(isset($query['spn'])) $iframe .= "&amp;spn=".$query['spn'];
if(isset($query['z'])) $iframe .= "&amp;z=".$query['z'];
if(isset($query['iwloc'])) $iframe .= "&amp;iwloc=".$query['iwloc']; else $iframe .= "&amp;iwloc=";
$iframe .= "&amp;output=embed\">";
$iframe .= "</iframe>";

这会产生类似这样的东西:

<iframe  src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=fr&amp;geocode=&amp;aq=&amp;t=m&amp;ie=UTF8&amp;ll=39.566752,2.649834&amp;spn=0.369997,0.837021&amp;z=11&amp;iwloc=&amp;output=embed" marginwidth="0" marginheight="0" scrolling="no" s12546768360786571550="true" replaced="true"></iframe>

它生成的 iframee 只给你谷歌地图选择的区域,你想让谷歌旅游添加这个 iframe:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.es/maps?cbll=39.566752,2.649834&amp;layer=c&amp;panoid=86s2yikaJz6n9Ezi7bJmTw&amp;cbp=12,113.38,,0,0&amp;ie=UTF8&amp;ll=39.566752,2.649834&amp;spn=0.369997,0.837021&amp;t=m&amp;z=11&amp;source=embed&amp;output=svembed"></iframe><br /><small><a href="https://maps.google.es/maps?cbll=39.566752,2.649834&amp;layer=c&amp;panoid=86s2yikaJz6n9Ezi7bJmTw&amp;cbp=12,113.38,,0,0&amp;ie=UTF8&amp;ll=39.566752,2.649834&amp;spn=0.369997,0.837021&amp;t=m&amp;z=11&amp;source=embed" style="color:#0000FF;text-align:left">Agrandir le plan</a></small>

DEMO

【讨论】:

  • 非常感谢您的分析,但是:https://www.google.es/maps/@39.566752,2.649834,3a,75y,113.38h,90t/data=!3m5!1e1!3m3!1s86s2yikaJz6n9Ezi7bJmTw!2e0!3e2&amp;output=embed 失败,您的意思是这样吗?
  • 嗨,我不太明白你在做什么。但是您的代码生成了这个 iframe:&lt;iframe marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;amp;source=s_q&amp;amp;hl=fr&amp;amp;geocode=&amp;amp;aq=&amp;amp;t=m&amp;amp;ie=UTF8&amp;amp;iwloc=&amp;amp;output=embed"&gt;&lt;/iframe&gt; 而不是游览:jsfiddle.net/7Ydbk 有什么想法吗?谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-25
  • 1970-01-01
  • 2011-12-04
  • 2012-04-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多