1
votes

I have a google map which I am getting json data from. I want to automatically build a string that I can pass to the marker object. I get an error "invalid object initializer" in firebug when I do this. Does this make sense or is their a better way to handle this.

function buildMarkers(json) {

    $.each(json, function(z) {     
        var asdf;
        $.each(this, function(key,valueObj){
            //console.log(key + '---' + valueObj);
            asdf += key + ': ' + valueObj + ', ';
        });


        markers[z] = new google.maps.Marker({
                map: map, 
                position: new google.maps.LatLng(this.school_lat,this.school_long),
                asdf
        });

etc.... 
1
looks like you're building a string, not key-value pairs - hunter
yes you're right, I want it to be object values... I believe? - Brian Barthold
which version of the GoogleMapsAPI? - hunter
I am using v3 of the api - Brian Barthold
Can you give an example of the JSON output? You are going to have to put together all of the MarkerOptions and pass them to Marker() at the same time. - Bryan Weaver

1 Answers

2
votes

try building your json object like this:

var asdf = [];
$.each(this, function(key, valueObj) {
    asdf.push({key: key, value: valueObj});
});