code Snippetlanguage CDNpackage_2 NPM
content_copy Copyopen_in_new Open
const map = L . map ( 'map' ). setView ([ 48.8566 , 2.3522 ], 5 );
L . tileLayer ( 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , {
tileSize: 256 ,
attribution: '© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}). addTo (map);
let marker, timeout;
const input = document. getElementById ( 'search-box' );
const results = document. getElementById ( 'results' );
input. addEventListener ( 'input' , () => {
clearTimeout (timeout);
const q = input.value. trim ();
if (q. length < 3 ) { results.style.display = 'none' ; return ; }
timeout = setTimeout ( async () => {
const res = await fetch ( 'https://api.maptiler.com/geocoding/' + encodeURIComponent (q) + '.json?key=YOUR_MAPTILER_KEY&limit=5' );
const data = await res. json ();
results.innerHTML = '' ;
results.style.display = data.features. length ? 'block' : 'none' ;
data.features. forEach ( f => {
const div = document. createElement ( 'div' );
div.textContent = f.place_name;
div. onclick = () => {
const [ lng , lat ] = f.center;
if (marker) marker. remove ();
marker = L . marker ([lat, lng]). addTo (map). bindPopup (f.place_name). openPopup ();
map. setView ([lat, lng], 14 );
results.style.display = 'none' ;
input.value = f.place_name;
};
results. appendChild (div);
});
}, 300 );
}); content_copy Copyopen_in_new Open
<! DOCTYPE html >
< html >
< head >
< meta charset = "utf-8" />
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" />
< link rel = "stylesheet" href = "https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
< script src = "https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" ></ script >
< style >
body { margin : 0 ; padding : 0 ; }
#map { width : 100 % ; height : 100 vh ; }
#search-box { position : absolute ; top : 10 px ; left : 50 px ; z-index : 1000 ; padding : 8 px 12 px ; font-size : 12 px ; font-family : monospace ; background : #141414 ; color : #e0e0e0 ; border : 2 px solid #2a2a2a ; width : 280 px ; }
#results { position : absolute ; top : 42 px ; left : 50 px ; z-index : 1000 ; background : #141414 ; border : 2 px solid #2a2a2a ; border-top : none ; width : 280 px ; max-height : 200 px ; overflow-y : auto ; display : none ; }
#results div { padding : 8 px 12 px ; cursor : pointer ; font-size : 11 px ; font-family : monospace ; color : #c0c0c0 ; border-bottom : 1 px solid #1e1e1e ; }
#results div :hover { background : #1a1a1a ; color : #e0e0e0 ; }
</ style >
</ head >
< body >
< div id = "map" ></ div >
< input id = "search-box" type = "text" placeholder = "Search address..." />
< div id = "results" ></ div >
< script >
const map = L . map ( 'map' ). setView ([ 48.8566 , 2.3522 ], 5 );
L . tileLayer ( 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , {
tileSize: 256 ,
attribution: '© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}). addTo (map);
let marker, timeout;
const input = document. getElementById ( 'search-box' );
const results = document. getElementById ( 'results' );
input. addEventListener ( 'input' , () => {
clearTimeout (timeout);
const q = input.value. trim ();
if (q. length < 3 ) { results.style.display = 'none' ; return ; }
timeout = setTimeout ( async () => {
const res = await fetch ( 'https://api.maptiler.com/geocoding/' + encodeURIComponent (q) + '.json?key=YOUR_MAPTILER_KEY&limit=5' );
const data = await res. json ();
results.innerHTML = '' ;
results.style.display = data.features. length ? 'block' : 'none' ;
data.features. forEach ( f => {
const div = document. createElement ( 'div' );
div.textContent = f.place_name;
div. onclick = () => {
const [ lng , lat ] = f.center;
if (marker) marker. remove ();
marker = L . marker ([lat, lng]). addTo (map). bindPopup (f.place_name). openPopup ();
map. setView ([lat, lng], 14 );
results.style.display = 'none' ;
input.value = f.place_name;
};
results. appendChild (div);
});
}, 300 );
});
</ script >
</ body >
</ html > content_copy Copyopen_in_new Open
import L from 'leaflet' ;
import 'leaflet/dist/leaflet.css' ;
const map = L . map ( 'map' ). setView ([ 48.8566 , 2.3522 ], 5 );
L . tileLayer ( 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , {
tileSize: 256 ,
attribution: '© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}). addTo (map);
let marker, timeout;
const input = document. getElementById ( 'search-box' );
const results = document. getElementById ( 'results' );
input. addEventListener ( 'input' , () => {
clearTimeout (timeout);
const q = input.value. trim ();
if (q. length < 3 ) { results.style.display = 'none' ; return ; }
timeout = setTimeout ( async () => {
const res = await fetch ( 'https://api.maptiler.com/geocoding/' + encodeURIComponent (q) + '.json?key=YOUR_MAPTILER_KEY&limit=5' );
const data = await res. json ();
results.innerHTML = '' ;
results.style.display = data.features. length ? 'block' : 'none' ;
data.features. forEach ( f => {
const div = document. createElement ( 'div' );
div.textContent = f.place_name;
div. onclick = () => {
const [ lng , lat ] = f.center;
if (marker) marker. remove ();
marker = L . marker ([lat, lng]). addTo (map). bindPopup (f.place_name). openPopup ();
map. setView ([lat, lng], 14 );
results.style.display = 'none' ;
input.value = f.place_name;
};
results. appendChild (div);
});
}, 300 );
});
const map = L.map('map').setView([48.8566, 2.3522], 5);
L.tileLayer('https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', {
tileSize: 256,
attribution: '© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
let marker, timeout;
const input = document.getElementById('search-box');
const results = document.getElementById('results');
input.addEventListener('input', () => {
clearTimeout(timeout);
const q = input.value.trim();
if (q.length < 3) { results.style.display = 'none'; return; }
timeout = setTimeout(async () => {
const res = await fetch('https://api.maptiler.com/geocoding/' + encodeURIComponent(q) + '.json?key=YOUR_MAPTILER_KEY&limit=5');
const data = await res.json();
results.innerHTML = '';
results.style.display = data.features.length ? 'block' : 'none';
data.features.forEach(f => {
const div = document.createElement('div');
div.textContent = f.place_name;
div.onclick = () => {
const [lng, lat] = f.center;
if (marker) marker.remove();
marker = L.marker([lat, lng]).addTo(map).bindPopup(f.place_name).openPopup();
map.setView([lat, lng], 14);
results.style.display = 'none';
input.value = f.place_name;
};
results.appendChild(div);
});
}, 300);
}); <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { width: 100%; height: 100vh; }
#search-box { position: absolute; top: 10px; left: 50px; z-index: 1000; padding: 8px 12px; font-size: 12px; font-family: monospace; background: #141414; color: #e0e0e0; border: 2px solid #2a2a2a; width: 280px; }
#results { position: absolute; top: 42px; left: 50px; z-index: 1000; background: #141414; border: 2px solid #2a2a2a; border-top: none; width: 280px; max-height: 200px; overflow-y: auto; display: none; }
#results div { padding: 8px 12px; cursor: pointer; font-size: 11px; font-family: monospace; color: #c0c0c0; border-bottom: 1px solid #1e1e1e; }
#results div:hover { background: #1a1a1a; color: #e0e0e0; }
</style>
</head>
<body>
<div id="map"></div>
<input id="search-box" type="text" placeholder="Search address..." />
<div id="results"></div>
<script>
const map = L.map('map').setView([48.8566, 2.3522], 5);
L.tileLayer('https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', {
tileSize: 256,
attribution: '© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
let marker, timeout;
const input = document.getElementById('search-box');
const results = document.getElementById('results');
input.addEventListener('input', () => {
clearTimeout(timeout);
const q = input.value.trim();
if (q.length < 3) { results.style.display = 'none'; return; }
timeout = setTimeout(async () => {
const res = await fetch('https://api.maptiler.com/geocoding/' + encodeURIComponent(q) + '.json?key=YOUR_MAPTILER_KEY&limit=5');
const data = await res.json();
results.innerHTML = '';
results.style.display = data.features.length ? 'block' : 'none';
data.features.forEach(f => {
const div = document.createElement('div');
div.textContent = f.place_name;
div.onclick = () => {
const [lng, lat] = f.center;
if (marker) marker.remove();
marker = L.marker([lat, lng]).addTo(map).bindPopup(f.place_name).openPopup();
map.setView([lat, lng], 14);
results.style.display = 'none';
input.value = f.place_name;
};
results.appendChild(div);
});
}, 300);
});
</script>
</body>
</html> import L from 'leaflet';
import 'leaflet/dist/leaflet.css';
const map = L.map('map').setView([48.8566, 2.3522], 5);
L.tileLayer('https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', {
tileSize: 256,
attribution: '© <a href="https://www.maptiler.com/">MapTiler</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
let marker, timeout;
const input = document.getElementById('search-box');
const results = document.getElementById('results');
input.addEventListener('input', () => {
clearTimeout(timeout);
const q = input.value.trim();
if (q.length < 3) { results.style.display = 'none'; return; }
timeout = setTimeout(async () => {
const res = await fetch('https://api.maptiler.com/geocoding/' + encodeURIComponent(q) + '.json?key=YOUR_MAPTILER_KEY&limit=5');
const data = await res.json();
results.innerHTML = '';
results.style.display = data.features.length ? 'block' : 'none';
data.features.forEach(f => {
const div = document.createElement('div');
div.textContent = f.place_name;
div.onclick = () => {
const [lng, lat] = f.center;
if (marker) marker.remove();
marker = L.marker([lat, lng]).addTo(map).bindPopup(f.place_name).openPopup();
map.setView([lat, lng], 14);
results.style.display = 'none';
input.value = f.place_name;
};
results.appendChild(div);
});
}, 300);
});