1

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.... 
5
  • looks like you're building a string, not key-value pairs Commented Dec 19, 2011 at 20:59
  • yes you're right, I want it to be object values... I believe? Commented Dec 19, 2011 at 21:01
  • which version of the GoogleMapsAPI? Commented Dec 19, 2011 at 21:07
  • I am using v3 of the api Commented Dec 19, 2011 at 21:10
  • 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. Commented Dec 19, 2011 at 21:23

1 Answer 1

2

try building your json object like this:

var asdf = [];
$.each(this, function(key, valueObj) {
    asdf.push({key: key, value: valueObj});
});
Sign up to request clarification or add additional context in comments.

Comments

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.