I am pulling in my marker data via JSON.
When i was developing my local copy i had this in a JS file and just called it using
<script src="assets/js/locations.js"></script>
I am now moving the site onto a CMS (ExpressionEngine) and because the marker data is dynamic I have a JS template which now holds the JSON data.
I now have to include the file as (notice that there is no file extension)
<script src="http://domain.com/map/locations"></script>
Here is an example of the JSON I have.
var locations = [
[2, 51.39006, -0.02976, 'telecommunications', 'Test 2', '<div><img src="http://localhost/map/assets/graphics/info_window/default.jpg" alt="Test 2" width="105" height="70" style="float:right;"> <p>fdgj fdh uhfj bfd nibjdfjb ndfjn fd vfn vbjdc ifs n ei klmvf.cx fi fskn d</p></div>', '<a href="http://www.yahoo.com" target="_blank">Read more</a>' ],
[1, 51.51400, -0.12002, 'transport', 'Test map marker', '<div><img src="{image:url:thumb}" alt="Test map marker" width="{image:width:thumb}" height="{image:height:thumb}" style="float:right;"> <p>eubnglrsk nekfldb jndklvcbv jdnfhl kvbmd klbndvl kbjn dkbnm lkd nbmfljeb ygdjfjn</p></div>', '<a href="http://www.google.com" target="_blank">Read more</a>' ]
];
This is the marker loop for the map
var markers = [];
// Looping through the JSON data
for (var i = 0; i < locations.length; i++) {
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
title: locations[i][4],
icon: iconSrc[locations[i][3]]
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent("<div class='cont_box' id='" + locations[i][0] + "'>" + "<h2>" +locations[i][4] + "</h2>" + "<div class='cont'>" + locations[i][5] + "</div><div style='clear:both;'></div><div class='link'>" + locations[i][6] + "</div></div>");
infoWindow.open(map, marker);
}
})(marker, i));
}// END for loop
Obviously the error I get when I reference the JSON data rendered by the CMS is ::
ReferenceError: locations is not defined
The URL is valid, just it doesn’t seem to be pulled in like when i use a JS file.
I don’t know if it would be better for me to call the file within the maps JS code itself.
Any suggestions on how I could make this work would be great
I have 2 ideas.
My other idea is to load your data in the code: