// Creating map options let mapOptions = { center: [41.875728, -87.626609], zoom: 10, } var defaultIcon = L.icon({ iconUrl: '/assets/icons/marker-icon.png', shadowUrl: '/assets/icons/marker-shadow.png', }); // Creating a map object let map = new L.map('map', mapOptions); // Creating a Layer object let layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }); // Geolocation L.control.locate().addTo(map); // Adding layer to the map map.addLayer(layer); // Marker let marker = null; map.on('click', (event)=> { if(marker !== null){ map.removeLayer(marker); } marker = L.marker([event.latlng.lat , event.latlng.lng], {icon: defaultIcon}).addTo(map); document.getElementById('lat').value = event.latlng.lat; document.getElementById('long').value = event.latlng.lng; })