I know a bit about what scope is, i am new to javascript and have hit a full stop in my code. Here is the code that i use.
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(37.775057,-122.419624),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
function clicked(id) {
$.ajax({
type: "GET",
url: 'response.php',
data: {id: id},
success: function (lats) {
var obj = $.parseJSON(lats);
var line = [];
for (var i = obj.length - 1; i >= 0; i--) {
line.push(new google.maps.LatLng(obj[i].latitude, obj[i].longitude));
};
var polyPath = new google.maps.Polyline({
path: line,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
polyPath.setMap(map);
console.log(polyPath);
}
});
return false;
}
Needless to say its google maps. Problem is that due to scope, javascript cant access the map variable that is required to draw the polylines. Help is highly appreciated!