New to javascript. Trying to add a list of markers (from python) to a google map.
My raw Jinja2 template:
<head>
<title>Google Map Test</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
#map-canvas { height: 700px; width: 400px; }
</style>
<script type="text/javascript"
src=";sensor=false">
</script>
<script type="text/javascript">
var locations = {{ locations|safe }};
/*
locations|safe results in the following line in my rendered template:
var locations = [['A.W. Hastings / Windows & Doors by Brownell', '44.4456', '-73.1276'], ['AARP', '44.4757', '-73.2113'], ['Adirondack Audiology', '44.4792', '-73.22'], ['Alchemy Jewelry Arts #1A', '44.4672', '-73.2147'], ['All Smiles Dental', '44.2334', '-72.5539']];
*/
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(43.953, -72.593),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (var i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
I send the list "locations" from my view because the list changes regularly.
I am receiving the Uncaught Reference Error for the line where I define the locations variable. The full output is:
Uncaught ReferenceError: None is not defined 127.0.0.1:14 (anonymous function)
New to javascript. Trying to add a list of markers (from python) to a google map.
My raw Jinja2 template:
<head>
<title>Google Map Test</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
#map-canvas { height: 700px; width: 400px; }
</style>
<script type="text/javascript"
src="https://maps.googleapis./maps/api/js?key=MY_API_KEY&sensor=false">
</script>
<script type="text/javascript">
var locations = {{ locations|safe }};
/*
locations|safe results in the following line in my rendered template:
var locations = [['A.W. Hastings / Windows & Doors by Brownell', '44.4456', '-73.1276'], ['AARP', '44.4757', '-73.2113'], ['Adirondack Audiology', '44.4792', '-73.22'], ['Alchemy Jewelry Arts #1A', '44.4672', '-73.2147'], ['All Smiles Dental', '44.2334', '-72.5539']];
*/
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(43.953, -72.593),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (var i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
I send the list "locations" from my view because the list changes regularly.
I am receiving the Uncaught Reference Error for the line where I define the locations variable. The full output is:
Uncaught ReferenceError: None is not defined 127.0.0.1:14 (anonymous function)
Share Improve this question asked May 6, 2013 at 17:48 Matt ParrillaMatt Parrilla 3,2216 gold badges36 silver badges54 bronze badges 3-
There must be some code referencing an undeclared identifier
None
to generate that error message, but I don't see it here. – Dagg Nabbit Commented May 6, 2013 at 18:06 - @DaggNabbit this is copied and pasted from my template. – Matt Parrilla Commented May 6, 2013 at 18:57
- *Though the output for the rendered template was truncated, and there is where I found "None" – Matt Parrilla Commented May 6, 2013 at 19:19
1 Answer
Reset to default 2Move the code that follows the function initialize()
inside the function, otherwise the variable map
is not available when and where you access it.