douju6752 2014-04-27 01:00
浏览 51

尝试使用ajax创建带有click函数的传单映射,将lat lng坐标发布到php文件中

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 &copy; <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 &copy; <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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?