Skip to content
Advertisement

React leaflet map center not changing

I’m setting up a map to find the coords of a person and then put that location on the map. But for some reason, the coords aren’t being shown on the map. I console.log to make sure the state variables(where the coords are being stored) were emitting the right coords and they are. I don’t know why the map won’t change to them though.

My code:

JavaScript

Advertisement

Answer

From the official docs

Except for its children, MapContainer props are immutable: changing them after they have been set a first time will have no effect on the Map instance or its container.

Use a child component that will change your map view upon position change

JavaScript

Use it like this:

JavaScript

Demo

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement