I have been trying to get this to work for quite a while now:
{% for record in records %}
var GPSlocation = "(37.7699298, -93.4469157)";
var LatLng = GPSlocation.replace("(", "").replace(")", "").split(", ")
var Lat = parseFloat(LatLng[0]);
var Lng = parseFloat(LatLng[1]);
var markerLatlng = new google.maps.LatLng(Lat, Lng);
var marker = new google.maps.Marker({
position: record.GPSlocation,
title: record.title
});
//add the marker to the map
marker.setMap(map);
{% endfor %}
And it works fine when I hard code the variables in there but otherwise I just won’t do anything. When I just print them out in the html I have all the data I wanted in the record variables but when I try to use it in JavaScript it just doesn’t work. Any ideas?
So I need to put a JSON encoding filter onto the Jinja2 system and I am guessing it would look something like this:
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
jinja_env.filters['json_encode'] = json.dumps,
autoescape = True)
Yes, but not like that. You could instead do something like this: