【发布时间】:2020-08-02 20:10:45
【问题描述】:
我正在构建一个 React 应用程序,并尝试在我的网站上嵌入 Google 地图方向。这是我的代码:
import React from "react";
import Iframe from "react-iframe";
export default (props) => {
return (
<Iframe
width="600"
height="450"
frameborder="0"
style="border:0"
src={`https://www.google.com/maps/embed/v1/directions
?key=<my_api_key>
&origin=Oslo+Norway
&destination=Telemark+Norway
&avoid=tolls|highways`}
allowfullscreen
/>
);
};
我遇到了很多人之前遇到的错误:
delivery-plan:1 Refused to display <url> in a frame because it set 'X-Frame-Options' to 'sameorigin'.
奇怪的是,当我更改为使用地点 API 的 URL 时,Iframe 变成了:
<Iframe
width="600"
height="450"
frameborder="0"
style="border:0"
src={`https://www.google.com/maps/embed/v1/place?key=<my_api-token>
&q=Space+Needle,Seattle+WA`}
allowfullscreen
/>
它完全可以找到。
请注意,这两个 URL 均直接取自 Google API documentation
【问题讨论】:
标签: reactjs google-maps iframe google-maps-api-3 google-maps-embed