I am having trouble with the goMap plugin for jquery. I want to obtain all the markers on my map, however, when calling the getMarkers() function, it returns an empty array.
I am guessing it has something to do with scopes?
I add the markers by querying the database with an ajax call.
$("#canvas").goMap({
latitude: 44.230065,
longitude: -76.50000,
zoom: 14,
maptype: 'ROADMAP'
});
load_markers();
function load_markers(query_url) {
if (query_url == undefined) {
query_url = '/posts/get_markers';
}
$.getJSON(query_url, function(data) {
$.each(data, function(pair) {
var id = data[pair]['posts']['id'];
$.goMap.createMarker({
latitude: data[pair]['posts']['lat'],
longitude: data[pair]['posts']['lng'],
draggable: false,
id: id,
html: {
ajax: "posts/ajax_show/"+id,
content: 'loading...',
popup: false
}
});
});
});
}
console.log(($.goMap.getMarkers()));
Thanks!
Try to print it in the success handler of the getJSON call, otherwise you don´t know if you got the data yet. More a timing issue than scope if im correct.