$( document ).ready(function() { // Create map var map = L.map('map').setView([47.218371,-1.553621], 13); L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', maxZoom: 18 }).addTo(map); // Create marker var marker = L.marker([47.218371,-1.553621], { draggable: true }).addTo(map); // every time the marker is dragged, update the coordinates container marker.on('dragend', ondragend); // Set the initial marker coordinate on load. ondragend(); function ondragend() { var m = marker.getLatLng(); $('latitude').value = m.lat; $('longitude').value = m.lng; } // Search sub form $('#search-btn').click(function(e){ e.preventDefault(); var btn = $(this).button('loading'); // Geocoding var searchString = $('#search').val(); $.getJSON('http://nominatim.openstreetmap.org/search?limit=5&format=json&q='+searchString, function(data){ var items = []; $.each(data, function(key, val) { items.push( "
  • " + val.display_name + '
  • ' ); }); $('#modal .modal-body').empty(); if (items.length != 0) { $('