I have multiple Google Maps on a single page.
Scenario:
Working Case: :)
Problem Case: :(
I am not able to understand how are the maps affecting each other even when there is no clash of variable names.
Also, how can the order of maps affect it?
It's because of the way you are loading the API and the StyledMarker extension. Do both only once, and as early as possible (preferably in the <head>
section).
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js?v=3.6&sensor=true&language=en-us"></script>
<script src="/site_media/js/google_maps/StyledMarker.js"></script>
</head>
Don't include the scripts anywhere else.
In the first example, you load the API, then do that again and then the StyledMarker extension, and then you call map1()
and map2()
. But because the StyledMarker extension is loaded last, everything works.
In the second example, you load the API and the StyledMarker extension, then you load the API again, then you call map1()
and attempt to use styled markers. However loading the API the second time may well have obliterated the StyledMarker extension.