I have the usual google maps api startup code:
function initialize() {
var mapOptions = {
zoom: 7,
zoomControl : false,
streetViewControl : false,
panControl : false,
scaleControl : true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
};
</script>
I also have a set of files that define overlays, like this:
var path12coords = [
//stuff
];
var path12 = new google.maps.Polyline({
path: path12coords,
strokeOpacity: 1.0,
strokeWeight: 2
});
path12.setMap(map);
This code has to go into the initialize() method, or is to be called in any other way on load. How do I put this into the code I have? I can do <script type="text/javascript" src="js/path12.js"></script>, but then the code is standalone and isn’t called on load.
Add it to the initialize function. If your code get’s big you can define your own functions and call these functions from within initialize.
If you want to use an external js file or not depends on if you want to reuse the code on other pages. And it depends on how big the code gets.