I'm trying to send a lat/long point as a JSON object from Python to a javascript. I'm using Flask so the following is Jinja templating..
Python:
@app.route('/')
def homepage():
lat_lng = (39.7392,-104.9847)
return render_template("index_v2.html", lat_lng=json.dumps(lat_lng))
html with js:
<script type='text/javascript'>
var map;
function initialize() {
// Create the map.
var lat_lng = eval('({{ lat_lng }})')
map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 8,
center: new google.maps.LatLng(lat_lng)
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
I'm using the eval because the standard Jinja notation of variable = {{ data }} isn't working and I found some advice that eval was necessary. Any advice?