I can't seem to add a marker to a map from within a callback function. I have this code.
var map;
$.get(url, function(data) {
var coordinates = JSON.parse(data);
var latlng = new google.maps.LatLng(coordinates[0], coordinates[1]);
var myOptions = {
center: latlng,
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker(
{ position: new google.maps.LatLng(41.7056381, -72.5559746),
map: map
});
});
The map shows up in the page fine but no marker. If I move all this code from outside the callback it works with the marker. Any thoughts? Been at this for two hours now.