using API Google Places details error Allow origin Cors React 项目

using API Google Places details error Allow origin Cors React project

我正在尝试使用 Google 地点 API 通过其 ID 获取地点的详细信息我正在使用此处提供的服务 https://developers.google.com/places/web-service/details

我正在 ReactJs 上开发

错误图片如下:

我在这里看到,对于这些 Allow Origin 情况,您应该使用 Maps JavaScript API --> https://developers.google.com/maps/documentation/javascript/places#place_details

然而,在 REACTJS 项目中获取 google.maps 引用的最佳方式是什么?

我会推荐 react-google-maps,它是基于组件的。它的社区很大。 这是 react-google-maps 中位置 API 的工作示例,请确保您有一个 API 密钥。 https://codesandbox.io/s/qqzm67ykmq

您需要首先获得一个 API 密钥 here。以下是 API 键的以下步骤:

  • 创建项目
  • 生成 API 密钥
  • 启用地点 API 和地图 Javascript API
  • 使用这些 API 限制您的 API 密钥