How to get marker coordinates to the "coordinates" variable to be sent using ajax?

google.maps.event.addListener(map, 'click', function(event) { if (marker != undefined) { marker.setMap(null); } latlng = event.latLng; var coordinates = latlng; $("body").on("click", "#button_save_coordinates", function(){ $.ajax({ type: "POST", url: "save_coordinates.php", cache: false, data: {"coordinates" : coordinates}, success: function(data){ alert(data); } }); }); marker = new google.maps.Marker({ position: latlng, clickable: true, map: map, title: 'title', animation: google.maps.Animation.DROP, visible: true }); }); 

This code does not want to send: (

    1 answer 1

    Get coordinates: Instead of:

     var coordinates = latlng; 

    Replaced by:

     var lat = latlng.lat(); var lng = latlng.lng(); var coordinates = lat+", "+lng;