0

I got "success" in the console which mean getjson returning an object. I try assign it to a var name news and put in back in showInfo but showInfo always output a loading image which mean typeof news is not defined. I try figure for many hours and still can not figuring it our. Please help !!!

function addMarker(place)
{

    var news;
    var my_lag = new google.maps.LatLng(place.latitude, place.longitude);
    var marker = new google.maps.Marker({
        position: my_lag,
        title : marker,
    });

    marker.setMap(map);

    $.getJSON(Flask.url_for('articles'), {geo: place.postal_code}, function(data){
            news = data;
            console.log("Success");
        }
    );

    google.maps.event.addListener(marker, "click", function(){
        showInfo(marker, news.title);
    });
}
0

getJSON is working. What does articles return? A list of json objects. Therefore what is news.title? Undefined.

2
  • In getJSON function, I assign news equal to data (according to the API, data should be what I get from getJSON). And data should have a titles in it. So, I try to showInfo back the title of that data (which is news) but it end up by news.title is not defined. May 15 '17 at 12:18
  • news is a list. news[0].title will have data in it. May 15 '17 at 12:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .