【问题标题】:How to display google map in Iframe如何在 iframe 中显示谷歌地图
【发布时间】:2016-02-11 00:44:29
【问题描述】:

我想在 Razor MVC 页面中显示谷歌地图,但它没有显示并收到如下错误:

拒绝在框架中显示“https://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&msid=XXXXXXXXXXXXXXX&ll=XXXXXXXXXX&spn=XXXXXXXXXX&output=embed”,因为它将“X-Frame-Options”设置为“SAMEORIGIN”。

代码如下:

<div id="map" style="width: 251px; height: 202px;">
  <iframe id="iGmap" width="251" height="202" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="
http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=XXXXXXXXXXXXXXXXXXXXX&amp;ll=XXXXXXXXXXXXXXXX&amp;spn=XXXXXXXXXXXXX&amp;output=embed">
  </iframe>
</div>

【问题讨论】:

    标签: javascript asp.net asp.net-mvc google-maps iframe


    【解决方案1】:

    Google 地图会阻止外部网站将其嵌入 iframe。这是他们的政策,所以这不是你可以规避的。如果您想在 iframe 中显示地图,则需要通过 Google Maps Embed API(或他们的其他 API 之一)来实现。

    【讨论】:

    • 好的..那么没有其他选择了吗?
    【解决方案2】:

    这是我通过删除“ms?”实现的来自我的网址

    http://maps.google.com/maps/ms?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=XXXXXXXXXXXXXXXXXXXXX&amp;ll=XXXXXXXXXXXXXXXX&amp;spn=XXXXXXXXXXXXX&amp;output=embed
    

    http://maps.google.com/maps?ie=UTF8&amp;hl=en&amp;msa=0&amp;msid=XXXXXXXXXXXXXXXXXXXXX&amp;ll=XXXXXXXXXXXXXXXX&amp;spn=XXXXXXXXXXXXX&amp;output=embed
    

    【讨论】:

      【解决方案3】:

      这样做

      <iframe src="https://www.google.com/maps/d/u/0/embed?mid=1-VlXsvMWMr8EotfMcIwYKt-1SrI" width="320" height="350" style="margin-top:-387px"></iframe>
      

      让我知道它是否有效

      【讨论】:

        猜你喜欢
        • 2014-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多