Skip to content

Instantly share code, notes, and snippets.

Last active May 10, 2018
What would you like to do?
Add leaflet points on click

Click on the map to add points. See the console for lat/long output.

<title>Adding or moving markers on a Leaflet map</title>
<meta charset="utf-8">
<link rel="stylesheet" href="" />
<script src=""></script>
<style type="text/css">
html, body, #map{
height: 100%;
padding: 0;
margin: 0;
<div id="map"></div>
<script type="text/javascript">
var options = {
center: [37.7749, -122.4194],
zoom: 10
var map ='map', options);
L.tileLayer('http://{s}{z}/{x}/{y}.png', {attribution: 'OSM'})
var coord = e.latlng.toString().split(',');
var lat = coord[0].split('(');
var lng = coord[1].split(')');
console.log("You clicked the map at LAT: " + lat[1] + " and LONG: " + lng[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment