Add markers from within jQuery $.get callback

39 views
Skip to first unread message

bennyhill

unread,
Jan 12, 2012, 5:45:36 PM1/12/12
to google-map...@googlegroups.com
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.  

Alan Pearce

unread,
Jan 13, 2012, 2:02:41 AM1/13/12
to Google Maps JavaScript API v3
If you could provide a link to the code running somewhere it would
help someone debug it.
Reply all
Reply to author
Forward
0 new messages