1

Here is the Marker reference

var markers = [];
var marker = new google.maps.Marker({ position: e.latLng, map: map });  
markers.push(marker); // add marker to the global array 

My loop to markers...

    var jsonObj = []; 
    for (var i = 0; i < markers.length; i++)
    {
        jsonObj.push({ latitude: markers[i].position, map: markers[i].map }); //key
    }

    alert(JSON.stringify(jsonObj)); // error 

1 Answer 1

2

The problem is that each marker has a reference to the map instance, and the map instance, has an array of markers (Which, redundantly, each one of them has a reference to map).

Sign up to request clarification or add additional context in comments.

2 Comments

I did not realized that I have the same key and that can be changed so instead of map: markers[i].map I can have something like mapKey: markers[i].map ?
I would not add the map instance at all. If you plan to have more than one map, I would create a key/value pair object with all map instances indexed by an id, and in your jsonObj instead of the whole map instace, store the id to retreive it later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.