react-geosuggest,而无需在index.html

时间:2018-09-21 14:00:37

标签: javascript reactjs google-maps-api-3

我想在我的应用中使用react-geosuggest

在自述文件中,我看到必须在:

中包含Google Maps Places API。
<!DOCTYPE html>
  <html>
  <head>
    …
    <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_HERE&libraries=places"></script>
  </head>
  <body>
    …
  </body>
</html>

应该将其导入index.html文件中。有什么方法可以避免在我的index.html文件中包含apikey?

我尝试例如:

import React from "react";
import PropTypes from "prop-types";

import Geosuggest from "react-geosuggest";
import { GOOGLE_MAPS_KEY } from "../../libs/apiKeys";

const LocationPicker = props =>
  <div>
    <script src={`https://maps.googleapis.com/maps/api/js?key=${GOOGLE_MAPS_KEY}&libraries=places`} />
    <Geosuggest />
  </div>;

LocationPicker.propTypes = {};

export default LocationPicker;

显然不起作用。

有什么想法吗? 谢谢

0 个答案:

没有答案