首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google-map-react:添加圆半径

google-map-react:添加圆半径
EN

Stack Overflow用户
提问于 2019-01-31 01:55:15
回答 2查看 2.7K关注 0票数 0

我想在我的center周围添加一个红色的圆半径。我正在使用这个包https://github.com/google-map-react/google-map-react,下面是我的代码:

代码语言:javascript
复制
<GoogleMapReact
      bootstrapURLKeys={{key: this.googleAPIKey}}
      defaultCenter={{lat: this.props.latitude, lng: this.props.longitude}}
      defaultZoom={this.props.zoom}
      yesIWantToUseGoogleMapApiInternals={true}
      onGoogleApiLoaded={({map, maps}) =>
        new google.maps.Circle({
          strokeColor: '#FF0000',
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: '#FF0000',
          fillOpacity: 0.3,
          map,
          center: {lat: this.props.latitude, lng: this.props.longitude},
          radius: 275,
        })}
        >
      <AnyReactComponent
        lat={this.props.latitude}
        lng={this.props.longitude}
      />
    </GoogleMapReact>

但是,我得到以下错误:

我遵循了文档中的说明,并尝试在googling上搜索如何解决此问题。有什么想法吗?

EN

回答 2

Stack Overflow用户

发布于 2019-03-01 21:27:36

只需这样做:

代码语言:javascript
复制
 onGoogleApiLoaded={({ map, maps }) =>
        new maps.Circle({
票数 3
EN

Stack Overflow用户

发布于 2019-02-01 20:36:15

显然,这个错误的发生是因为Google Maps API无法加载/或者它在 onGoogleApiLoaded函数被调用之后被加载,这就是这个错误发生的原因。然而,由于问题中没有提供足够的细节,目前还不清楚为什么Google Maps API无法加载。

根据google_map.js的说法,控制台中应该显示一些关于错误的附加细节,这可能会揭示错误发生的原因:

代码语言:javascript
复制
.catch(function (e) {
    // notify callback of load failure
    _this._onGoogleApiLoaded({ map: null, maps: null });
    console.error(e); // eslint-disable-line no-console
    throw e;
 });

但是这个例子看起来是正确的,这个demo演示了如何画一个圆。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54446707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档