I have the below react class which fetches the geolocation through the browser.
I am mapping a leaflet map. I want to geolocation to be an input to the setView, for
In addition to @IvanSanchez's response, You could add the geolocation and L.map(...) code to componentDidMount() React lifecycle method (depending on what other goals you hope to achieve). You could also create and bind event handlers for location found as well.
This way must have been added the dom and leaflet can find it.
Happy to help with this if it's still unclear.
I hope this helps if you are using Angular:
const container = document.getElementById('map')
if(container) {
// code to render map here...
}
The <div id="leafletmap">
must be added to the dom before calling L.map('leafletmap')
.