I need to get the JSON object data out of the callback function so that I can process it later in page, not within the callback as I am now. It must be obvious to everyone else as I can't see anything written about it. Can anyone tell me how to do it?
Here is my code:
<script type="text/javascript" src="/site_media/js/jstree/_lib/jquery.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var myOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
return map;
}
function add_marker(map, lat, long) {
var marker_image='/site_media/images/map_marker.png';
var myLatlng = new google.maps.LatLng(lat,long);
title='title';
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:title,
icon:marker_image
});
//map.panTo(myLatlng);
}
//window.onload=initialize();
setTimeout('map=initialize();',2000);
$.getJSON("/ajax/get", function(data) {
$.each(data, function(i,val) {
latitude = val.fields.latitude;
longitude = val.fields.longitude;
add_marker(map, latitude, longitude);
});
});
</script>
<div id="map_canvas" style="width: 500px; height: 300px"></div>