Leaflet demo

For update marker position

by denvut

HTML

<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css">
<div id="map"></div>

CSS

#map {
    height: 500px;
    width: 80%;
}

JavaScript

// We’ll add a tile layer to add to our map, in this case it’s a OSM tile layer.
	 	// Creating a tile layer usually involves setting the URL template for the tile images
	 	var osmUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
	 	    osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
	 	    osm = L.tileLayer(osmUrl, {
	 	        maxZoom: 18,
	 	        attribution: osmAttrib
	 	    });

	 	// initialize the map on the "map" div with a given center and zoom
	 	var map = L.map('map').setView([19.04469, 72.9258], 12).addLayer(osm);


	 	// Script for adding marker on map click
	 	function onMapClick(e) {
    alert(e.latlng.toString().length);
		
	 	   alert('3');
       loc1 = new L.marker(e.latlng, {draggable: 'true'});
       if (loc1 == null){ 
            loc1.on('dragend', function(event) {
                //отправляем запрос маршрута
            });
       map.addLayer(loc1);
    }
   
   else {alert('latlng');}
   
	 	}
map.on('click', function(e) {
        onMapClick(e);
    });