Reputation: 470
I am drawing a line using Google Maps V3, and I want to be able to pass a local variable loc
as global, so I can use it outside of this entire code. How can I do this?
if(this.flightdetails.route_details.length > 0)
{
$.each(this.flightdetails.posreports, function(i, nav)
{
var loc = new google.maps.LatLng(nav.latitude, nav.longitude);
// Rest of code
path[path.length] = loc;
focus_bounds.extend(loc);
});
}
Upvotes: 0
Views: 70
Reputation: 6253
Define your variable global:
var loc; // global
if(this.flightdetails.route_details.length > 0)
{
$.each(this.flightdetails.posreports, function(i, nav)
{
loc = new google.maps.LatLng(nav.latitude, nav.longitude); // with no var
// Rest of code
path[path.length] = loc;
focus_bounds.extend(loc);
});
}
Upvotes: 1
Reputation: 41958
var loc;
if(this.flightdetails.route_details.length > 0)
{
$.each(this.flightdetails.posreports, function(i, nav)
{
loc = new google.maps.LatLng(nav.latitude, nav.longitude);
// Rest of code
path[path.length] = loc;
focus_bounds.extend(loc);
});
}
console.log(loc);
Upvotes: 2