I'm trying to create Leaflet map that when the map is clicked on, it creates a marker and posts the coordinates in the console. Then the coordinates are posted via ajax to a php file and then inserted into a mysql database.
var map;
var centerlatlng = L.latLng(34.248987,-118.531891);
var lat;
var lng;
var markerLatLng;
$(document).ready(function (){
$('.aPopOver').popover({
'container': 'body'
});// this works
var aLayerOne = L.tileLayer('http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png', {
key: 'f4cedc5a042746e8813e1db9697e92e5',
styleId: 22677,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a>, Created @ <a href="http://www.csun.edu/csbs/departments/geography/">CSUN Geography</a>',
maxZoom: 18,
minZoom: 4
});
var aLayerTwo = L.tileLayer('http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png', {
key: 'f4cedc5a042746e8813e1db9697e92e5',
styleId: 82102,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a>, Created @ <a href="http://www.csun.edu/csbs/departments/geography/">CSUN Geography</a>',
maxZoom: 18,
minZoom: 4
});
map = L.map('myMap', {
center: centerlatlng,
zoom: 12,
layers: [aLayerOne]
});
// Define an EVENT for the map
map.on('click', function(e) {
console.log("You clicked on the map !");
console.info("lat = " + e.latlng.lat + " " + "long= " + e.latlng.lng);
var lat = $(e.latlng.lat);
var lng = $(e.latlng,lng);
var markerLatLng = L.marker([e.latlng.lat,e.latlng.lng]).addTo(map);
$.ajax({
type:"post",
url: "post.php",
data:{lat: lat},
success:function()
{
alert("Post Successful!");
}
});
}); // end of map on click event
// Add a Layers Control
var baseMaps = {
"Default": aLayerOne,
"Night Rider": aLayerTwo
};
L.control.layers(baseMaps).addTo(map);
// Add a Scale Control
L.control.scale().addTo(map);
// Add a Full Screen Control
// use "new" in its construct
new L.Control.FullScreen().addTo(map);
// Add a Locate Control
// images folder must be within the same folder as L.Control.Locate.css file
}); // end document ready