Harry Wood
home
>
maps
>
examples
> leaflet >
OpenCageData search box
OpenCageData search box
Leaflet map with a search box provided as a leaflet plugin by
OpenCageData
.
<html> <head> <title>OpenCageData search box</title> <script src="leaflet/leaflet.js"></script> <link rel="stylesheet" href="leaflet/leaflet.css" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/opencagedata/leaflet-opencage-geocoding@v2.0.0/dist/css/L.Control.OpenCageGeocoding.min.css" /> <script src="https://cdn.jsdelivr.net/gh/opencagedata/leaflet-opencage-geocoding@v2.0.0/dist/js/L.Control.OpenCageGeocoding.min.js"></script> <style> html, body, #map { height:100%; width:100%; padding:0; margin:0; } </style> <script language="javascript"> function init() { var map = L.map('map'); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors', maxZoom: 18 }).addTo(map); map.attributionControl.setPrefix(''); // Don't show the 'Powered by Leaflet' text. var options = { key: 'YOUR API KEY FROM OPENCAGEDATA', limit: 5, proximity: '51.505, -0.09' // favour results near here }; var control = L.Control.openCageGeocoding(options).addTo(map); var london = new L.LatLng(51.505, -0.09); map.setView(london, 13); } </script> </head> <body onLoad="javascript:init();"> <div id="map"></div> </body> </html>
view directly
Home
Blog
About
Maps
Other
Contact