如何在 Iframe 中显示 google 地图

问题描述 投票:0回答:4

我想在 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”到“同源”。

代码如下:

<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
4个回答
0
投票

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


0
投票

我通过删除“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

0
投票

这样做

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

如果有效请告诉我


0
投票

所有地图嵌入 API 请求均免费提供且无限制使用。

要在网页上创建嵌入式地图,您应该首先完成此链接中所需的设置步骤。

如果完成了第一步,您现在可以将 Maps Embed API URL 设置为 iframe 的 src 属性,如下所示:

<iframe
  width="600"
  height="450"
  style="border:0"
  loading="lazy"
  allowfullscreen
  referrerpolicy="no-referrer-when-downgrade"
  src="https://www.google.com/maps/embed/v1/place?key=API_KEY
  &q=Space+Needle,Seattle+WA">
</iframe>

希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.