Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This is my google map code. I'm trying to update new latitude and longitude when i moved the existing marker to new position. But I don't understand why the following google map code is not updating the new latitude and longitude when i moved it to new position. Can you tell me what is the wrong in my code?

<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src=" 
<script type="text/javascript">
$(document).ready(function() {

var mapCenter = new google.maps.LatLng(23.709920999999998,90.40714299999999); //Google map Coordinates
//var mapCenter = new google.maps.LatLng(48.856614,2.352222); //Google map Coordinates

var map;

map_initialize(); // initialize google map

//############### Google Map Initialize ##############
function map_initialize()
        var googleMapOptions = 
            center: mapCenter, // map center
            zoom: 16, //zoom level, 0 = earth view to higher value
            maxZoom: 22,
            minZoom: 2,
            zoomControlOptions: {
            style: google.maps.ZoomControlStyle.SMALL //zoom control size
            scaleControl: true, // enable scale control             
            mapTypeId: google.maps.MapTypeId.ROADMAP // google map type

        map = new google.maps.Map(document.getElementById("google_map"), googleMapOptions);         

        //Load Markers from the XML File, Check (map_process.php)
        $.get("map_process.php", function (data) {
            $(data).find("marker").each(function () {
                  var name      = $(this).attr('name');
                  var id        = $(this).attr('locId');
                  var uid       = $(this).attr('userid');
                  var address   = '<p>'+ $(this).attr('address') +'</p>';
                  var type      = $(this).attr('type');
                  var point     = new google.maps.LatLng(parseFloat($(this).attr('latitude')),parseFloat($(this).attr('longitude')));
                  create_marker(point, name, id, uid, address, false, false, false, "icons/blue-icon.png");

        //Right Click to Drop a New Marker
        google.maps.event.addListener(map, 'rightclick', function(event) {
            //Edit form to be displayed with new marker
            var EditForm = '<p><div class="marker-edit">'+
            '<form action="ajax-save.php" method="POST" name="SaveMarker" id="SaveMarker">'+
            '<label for="pName"><span>Place Name :</span><input type="text" name="pName" class="save-name" placeholder="Enter Title" maxlength="40" /></label>'+
            '<label for="pDesc"><span>Description :</span><textarea name="pDesc" class="save-desc" placeholder="Enter Address" maxlength="150"></textarea></label>'+                
            '</div></p><button name="save-marker" class="save-marker">Save Marker Details</button>';
            //Drop a new Marker with our Edit Form
            create_marker(event.latLng, 'New Marker',id=0, uid =0, EditForm, true, true, true, "icons/purple.png");


//############### Create Marker Function ##############
function create_marker(MapPos, MapTitle, idd, uid, MapDesc,  InfoOpenDefault, DragAble, Removable, iconPath)

    //new marker
    var marker = new google.maps.Marker({
        position: MapPos,
        map: map,
        animation: google.maps.Animation.DROP,
        title:"Hello World!",
        icon: iconPath

    //Content structure of info Window for the Markers
    var contentString = $('<div class="marker-info-win">'+
    '<div class="marker-inner-win"><span class="info-content">'+
    '<h1 class="marker-heading">'+MapTitle+'</h1>'+

    '</span><button name="remove-marker" class="remove-marker" title="Remove Marker">Remove Marker</button>'+
    '</span><button name="update-marker" class="update-marker" title="Update Marker">Update Marker</button>'+               

    //Create an infoWindow
    var infowindow = new google.maps.InfoWindow();
    //set the content of infoWindow

    //Find remove button in infoWindow
    var removeBtn   = contentString.find('button.remove-marker')[0];
    var saveBtn     = contentString.find('')[0];
    var updateBtn   = contentString.find('button.update-marker')[0];

    //add click listner to remove marker button
    google.maps.event.addDomListener(removeBtn, "click", function(event) {
    //add click listner to remove marker button
    google.maps.event.addDomListener(updateBtn, "dragend", function(event) {
        update_marker(marker,MapTitle, idd, uid, MapDesc);

    if(typeof saveBtn !== 'undefined') //continue only when save button is present
        //add click listner to save marker button
        google.maps.event.addDomListener(saveBtn, "click", function(event) {
            var mReplace = contentString.find(''); //html to be replaced after success
            var mName = contentString.find('')[0].value; //name input field value
            var mDesc  = contentString.find('')[0].value; //description input field value
            var mType = contentString.find('')[0].value; //type of marker
            var psType = contentString.find('')[0].value; //type of marker

                save_marker(marker, mName, mDesc, mType, psType, mReplace); //call save marker function


    //add click listner to save marker button        
    google.maps.event.addListener(marker, 'click', function() {
  ,marker); // click on marker opens info window 

    if(InfoOpenDefault) //whether info window should be open by default

function update_marker(Marker, mName, idd, uid, mAddress)
    //Save new marker using jQuery Ajax
    var mLatLang = Marker.getPosition().toUrlValue(); //get marker position
    var myData = {update : 'true',name : mName, address : mAddress, id:idd, userid: uid,latlang : mLatLang }; //post variables
      type: "POST",
      url: "map_update.php",
      data: myData,
            //replaceWin.html(data); //replace info window with new html
            Marker.setDraggable(true); //set marker to fixed
            Marker.setIcon('icons/blue_icon.png'); //replace icon
        error:function (xhr, ajaxOptions, thrownError){
            alert(thrownError); //throw any errors

share|improve this question

closed as off-topic by Get Spatial, PolyGeo Aug 3 at 21:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example" – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

I found it....yea..... – creativeartbd Nov 5 '13 at 14:14
map.panTo(laLatLng);… – Mapperz Nov 5 '13 at 14:31
@creativeartbd, if you now have the solution to your answer, please consider posting an answer to your own question. – Andre Silva Nov 5 '13 at 17:17