【问题标题】:using API Google Places details error Allow origin Cors React project使用 API Google Places 详细信息错误 Allow origin Cors React project
【发布时间】:2019-02-01 05:53:14
【问题描述】:

我正在尝试使用 Google Place 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 引用的最佳方法是什么?

【问题讨论】:

    标签: reactjs google-maps cors google-places-api


    【解决方案1】:

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

    您首先需要从here 获取 API 密钥。以下是 API 密钥的以下步骤:

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

    【讨论】:

    • 谢谢萨克尼!我使用香草javascript解决了使用此代码github.com/elharony/…作为参考..当组件已经安装时,将带有google Api URL的脚本标签添加到DOM中..工作正常:)
    猜你喜欢
    • 2016-11-27
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2012-12-23
    • 2016-07-13
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    相关资源
    最近更新 更多