您已在此页面上多次包含Google Maps JavaScript API

卡姆兰

我该如何避免“您已在此页面上多次包含Google Maps JavaScript API。这可能会导致意外错误。” 如果我正在使用google-map-react来显示地图并在另一个组件中进行react-places-autocomplete以获取地址和坐标?

//LocationMapPage  component that displays the map box and pass the props to it
class LocationMapPage extends Component {

  render() {
    let {latLng,name,address} = this.props.location;
    return (
        <MapBox lat={latLng.lat} lng={latLng.lng} name={name} address={address}/>
    )
  }

}

//MapBox component
import React from "react";
import GoogleMapReact from 'google-map-react';
import apiKey from "../../configureMap";


const Marker = () => <i className="fa fa-map-marker fa-2x text-danger" />

const MapBox = ({lat,lng, name, address}) => {
    const center = [lat,lng];
    const zoom = 14;
    return (  
        <div style={{ height: '300px', width: '100%' }}>
            <GoogleMapReact
            bootstrapURLKeys={{ key: apiKey }}
            defaultCenter={center}
            defaultZoom={zoom}
            >
            <Marker
                lat={lat}
                lng={lng}
                text={`${name}, ${address}`}
            />
            </GoogleMapReact>
      </div>
    );
}

export default MapBox; 

地图为空白:在此处输入图片说明控制台中的错误:您已在此页面上多次包含Google Maps JavaScript API。这可能会导致意外错误。

怎么解决?

我在项目中使用google-map-reactreact-places-autocomplete

卡姆兰

作为我在两个不同组件中使用google map API的特定用例的临时解决方案,我刚刚在index.html中添加了脚本:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script> 

我这样做是为了避免React-places-autocomplete GitHub页面上的文档中的特定错误

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

“您已在此页面上多次包含Google Maps API”错误

修复“您已在此页面上多次包含Google Maps API。这可能会导致意外错误。”

同一页面上有两个不同的Google API,但您在此页面上多次包含Google Maps API错误

Google Maps JavaScript API - 结算

流星Google Maps JavaScript API

Google Maps Javascript API 计费

Google Maps Javascript API与Google Maps Embed API

无法获取Google Maps JavaScript API密钥

Google Maps Javascript API 204错误

Google Maps Javascript API - 图例最大高度

Google Maps Javascript API基于云的样式

Google Maps API Javascript;TypeError a为null

Google Maps Javascript API / Streetview FOV

Google Maps Javascript API 未呈现

多次包含Google Maps JavaScript API + initMap不是一个函数(无效值)

这里Maps Javascript API

Google Maps JavaScript API错误:启用了Google Maps JavaScript API的ApiNotActivatedMapError

此页面上的Google Maps API多次-Modal Bootstrap Return Json Success

使用 react-google-maps 和 react-places-autocomplete 时出现“Google Maps JavaScript API 多次”错误

Google Maps JavaScript API v3 /数据层/ MarkerClusterer

如何在HTML JavaScript中验证Google Maps API密钥?

在 iFrame 中使用带有地图的 Google Maps JavaScript API

Javascript Google Maps api addDomListener更改此上下文

Google Maps Javascript API填充建筑物的颜色

Google Maps API Javascript将onclick添加到infowindow

SyntaxError: missing : 在使用 Google Maps Javascript API 的属性 id 之后

Google Maps Javascript API无法加载最接近的缩放级别?

JavaScript Google Maps API-更改标记的标题

Google Maps JavaScript API V3-显示多条路线