I have a few collections of markers that each have their own life-cycles, states and stores, independent of other groups or the map itself. I feel this could be easily managed if I could make a parent component for each type of marker, but not sure how or even if it's the best way.
Does anyone have any thoughts on this?
Cheers
Have you tried:
<Map>
<OneComponent />
<SecondComponent />
</Map>
And then mapping the Markers within those components?
I'm still not entirely sure how that'd work. Just rough-coding here, I'm envisaging something like this:
<Map>
<WhaleMarkers props={WhaleCoordinatesArray} />
<DolphinMarkers props={DolphinCoordinatesArray} />
</Map>
With WhaleMarkers and DolphinMarkers being a component that maps() the arrays to render a list of Markers.. but you can't just render a list of Marker components, you have to put them in a wrapper element of some sort. This then breaks the map, as the markers need to appear directly in the map, with no wrapper element in between, as far as I understand.
I am having the same issue. as soon as you wrap the
Has anyone found a solution for this yet?
Doubtful. After looking over at a lot of the source, this component is severely limited in regards to interaction between map elements and user events. Bit disappointed to have wasted an extensive amount of time dealing with this module.
I wanted to loop over my data that came from a .json file. So, I used map() to loop over them and display as many markers as my database's places have.
Unfortunately, I tried 2 solutions and both of them fail:
<Marker> inside a div: Well, this doesn't work and nothing was showing at all!!<Marker>
<InfoWindow>
</InfoWindow>
</Marker>
It works and displays my markers all over the map. BUT, the InfoWindow doesn't open!
If anyone finds a solution, please let me know!
_I am new to React!_
This issue happens because the component passes a set of internal props to all its children (https://github.com/fullstackreact/google-maps-react/blob/master/src/index.js#L232). If you have <Marker />s inside of another element (as you need to when you render them dynamically) the necessary props are passed to the element the markers are wrapped in, rather than the markers themselves.
To get around this create a component that renders a list of markers and explicitly pass the props through:
const Markers = props => (
myMarkers.map(marker =>
<Marker
{...props}
key={marker.id}
title={marker.name}
/>
)
);
And use it inside of Map:
<Map>
<Markers />
</Map>
Has anyone solved this issue?
Hi @ayushikhetan ,
I don't think so.
But I've created a Tutorial, you can find it here:
https://www.youtube.com/watch?v=nDJ00zO9X2U
@djgrant do you pass anything to <Markers />?
Most helpful comment
This issue happens because the component passes a set of internal props to all its children (https://github.com/fullstackreact/google-maps-react/blob/master/src/index.js#L232). If you have
<Marker />s inside of another element (as you need to when you render them dynamically) the necessary props are passed to the element the markers are wrapped in, rather than the markers themselves.To get around this create a component that renders a list of markers and explicitly pass the props through:
And use it inside of Map: