<!-- Replace <YOUR_API_ACCESS_TOKEN> with your LocationIQ token before using this code. -->
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>With Autocomplete API</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://tiles.locationiq.com/v3/libs/maplibre-gl/5.24.0/maplibre-gl.js?v=0.1.9'></script>
<link href='https://tiles.locationiq.com/v3/libs/maplibre-gl/5.24.0/maplibre-gl.css?v=0.1.9' rel='stylesheet' />
<script src='https://tiles.locationiq.com/v3/libs/liq/liq-styles-ctrl-libre-gl-v5.js?v=0.1.9'></script>
<link href='https://tiles.locationiq.com/v3/css/liq-styles-ctrl-libre-gl.css?v=0.1.9' rel="stylesheet" />
<!-- Include the geocoder control -->
<script src="https://tiles.locationiq.com/v3/libs/gl-geocoder/5.0.0/locationiq-gl-geocoder.min.js?v=0.1.9"></script>
<link rel="stylesheet" href="https://tiles.locationiq.com/v3/libs/gl-geocoder/5.0.0/locationiq-gl-geocoder.css?v=0.1.9" type="text/css" />
<!-- Promise polyfill script required to use the geocoder in IE 11 -->
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js"></script>
<style>
body { margin:0px; padding:0px; }
#map { position:absolute; top:0px; bottom:0px; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
//Add your LocationIQ Access Token here - https://my.locationiq.com/
locationiq.key = '<YOUR_API_ACCESS_TOKEN>';
//Define the map and configure the map's theme
var map = new maplibregl.Map({
container: 'map',
style: locationiq.getLayer("Streets"),
zoom: 12,
center: [-122.42, 37.779]
});
//Add Geocoder control to the map
var locationiqGeocoder = new LocationIQGeocoder({
accessToken: locationiq.key,
maplibregl: maplibregl,
limit: 5,
dedupe: 1,
normalizecity: 1,
bounded: 0,
importancesort: 0,
marker: {
color: 'red'
},
flyTo: {
screenSpeed: 7,
speed: 4
}
});
map.addControl(locationiqGeocoder, 'top-left');
</script>
</body>
</html>