zcreativelabs / react-simple-maps

Beautiful React SVG maps with d3-geo and topojson using a declarative api.
https://www.react-simple-maps.io/
MIT License
3.07k stars 424 forks source link

TypeError: Invalid attempt to destructure non-iterable instance > when adding markers #224

Closed jabusir closed 4 years ago

jabusir commented 4 years ago

Hi, I'm attempting to add markers to my map, but I keep getting this error when using the Marker component from react-simple-maps.

I have a functional component with a hook that is an array of objects, each with the property of "name", and "coordinates". In the return of my functional component, I map over the hook called markers, and return a Marker component for each with a key, and coordinates is set to marker.coordinates which has already been double checked to be an array of two numbers.

I've attached my code. Could really use some help thanks.

image

zimrick commented 4 years ago

Hi @jabusir,

The issue I see with the code above is that the coordinates you have are formatted in a way that will not work with react-simple-maps. They need to be [longitude, latitude]. In the case of San Jose that would be [-121.8863, 37.3382], since San Jose is 121.8° West of the Prime Meridian. Currently, your marker is rendered outside the defined area for the Albers USA projection. With that specific projection this will lead to errors.

So you have to reverse the order of your coordinates and make sure that the longitude is negative, otherwise [121.8, 37.3] will give you a marker somewhere in Shandong province in China, which will also result in an error, since it's outside the bounds of Albers USA.

Hope this helps!

jabusir commented 4 years ago

Thanks @zimrick,

I eventually figured out how to get it working, but couldn't figure out what the logic behind it was. Thank you for explaining.

XHIIHIIHX commented 2 years ago

How can you tell if the coordinates are valid before it throws the error?

PoojaSSW commented 1 year ago

hi @jabusir : I'm facing similar issue. Do you mind sharing your final solution that is working for you