const map = L.map('my-map').setView([48.1500327, 11.5753989], 15);
const myAPIKey = "6dc7fb95a3b246cfa0f3bcef5ce9ed9a";
const isRetina = L.Browser.retina;
const baseUrl = "https://maps.geoapify.com/v1/tile/osm-bright/{z}/{x}/{y}.png?apiKey={apiKey}";
const retinaUrl = "https://maps.geoapify.com/v1/tile/osm-bright/{z}/{x}/{y}@2x.png?apiKey={apiKey}";
map.attributionControl.setPrefix('Powered by <a href="https://www.geoapify.com/" target="_blank">Geoapify</a>')
L.tileLayer(isRetina ? retinaUrl : baseUrl, {
attribution: '<a href="https://openmaptiles.org/" target="_blank">© OpenMapTiles</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap</a> contributors',
map.zoomControl.remove();
const reverseGeocodingUrl = `https://api.geoapify.com/v1/geocode/reverse?lat=${e.latlng.lat}&lon=${e.latlng.lng}&apiKey=${myAPIKey}`;
fetch(reverseGeocodingUrl).then(result => result.json())
.then(featureCollection => {
if (featureCollection.features.length === 0) {
document.getElementById("status").textContent = "The address is not found";
const foundAddress = featureCollection.features[0];
document.getElementById("name").value = foundAddress.properties.name || '';
document.getElementById("house-number").value = foundAddress.properties.housenumber || '';
document.getElementById("street").value = foundAddress.properties.street || '';
document.getElementById("postcode").value = foundAddress.properties.postcode || '';
document.getElementById("city").value = foundAddress.properties.city || '';
document.getElementById("state").value = foundAddress.properties.state || '';
document.getElementById("country").value = foundAddress.properties.country || '';
document.getElementById("status").textContent = `Found address: ${foundAddress.properties.formatted}`;
marker = L.marker(new L.LatLng(foundAddress.properties.lat, foundAddress.properties.lon)).addTo(map);
map.on('click', onMapClick);