alexandra-c / leaflet-tracking-marker

✈ A React Leaflet library that allows developers to create custom markers that drifts to a certain point, computes their bearing angle using given coordinates and rotates accordingly.
MIT License
40 stars 13 forks source link

Error: Invalid LatLng object: (undefined, undefined) #10

Closed MoussaRiad closed 2 years ago

MoussaRiad commented 2 years ago

Describe the bug I have added the leaflet-tracking-marker to my project( which is for now a map with simple markers), and followed the same code example hosted in codesandbox link , But it doesn't rendering anything ( the hole map), and it showed me in the console this error : Uncaught Error: Invalid LatLng object: (undefined, undefined)

alexandra-c commented 2 years ago

Hello @MoussaRiad,

const [currentTrack, setCurrentTrack] = useState({});

In my example, the "currentTrack" is an object not an array, it represents one coordinate of your marker, latitude and longitude, defined by an object with two properties, "lat" and "lng".

I then destructure this "data" object and send its "lat" and "lng" values to the tracking marker as an array (see the code snippet bellow) image

But this is just my example, you can handle your data differently in your project as long as you make sure that you are sending the "position" and "prevPos" to LeafletTrackingMarker in the required format.

<LeafletTrackingMarker icon={icon} position={[latitude, longitude]} previousPosition={[previousLatitude, previousLongitude]} />