最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Not able to render the infoWindow in react-google-maps - Stack Overflow

programmeradmin0浏览0评论

I was trying to add an InfoWindow to the mid point of a polyline.

This is my code for displaying the infoWindow.

<InfoWindow
   position={this.state.windowPosition}
   onCloseclick={this.toggleInfoWindow}
   options={{pixelOffset: new google.maps.Size(0,-30)}}
>
       <p>iggd</p>
</InfoWindow>

windowPosition here is the lat and lng of the midpoint of the polyline. When I try to run this I am getting an error saying that You must provide either an anchor (typically render it inside a <Marker>) or a position props for <InfoWindow>. But the owner of the repo said that (link's here) we can render an infoWindow where ever we want if we pass a position as props which I am doing.

Any help is appreciated.

I was trying to add an InfoWindow to the mid point of a polyline.

This is my code for displaying the infoWindow.

<InfoWindow
   position={this.state.windowPosition}
   onCloseclick={this.toggleInfoWindow}
   options={{pixelOffset: new google.maps.Size(0,-30)}}
>
       <p>iggd</p>
</InfoWindow>

windowPosition here is the lat and lng of the midpoint of the polyline. When I try to run this I am getting an error saying that You must provide either an anchor (typically render it inside a <Marker>) or a position props for <InfoWindow>. But the owner of the repo said that (link's here) we can render an infoWindow where ever we want if we pass a position as props which I am doing.

Any help is appreciated.

Share Improve this question asked Feb 10, 2018 at 9:52 vineethvineeth 431 silver badge4 bronze badges 1
  • What value do you get when you console.log(this.state.windowPosition) right before your InfoWindow ponent? – Iavor Commented Feb 10, 2018 at 14:17
Add a ment  | 

1 Answer 1

Reset to default 4

You could do something like this:

            {this.state.position && 
                 <InfoWindow position={this.state.position}>
                     <h1>My InfoWindow</h1>
                 </InfoWindow>
             }

This topic is discussed here.

发布评论

评论列表(0)

  1. 暂无评论