In my flask GIS app, I am passing my web map a list of coordinates from a route in my Python backend, which works as I expect it to. When I print the list it looks like this.
[['53.792614', '-1.789202'], ['53.792561', '-1.789223'], ['53.770554', '-1.751224'], ['53.712614', '-1.746287']] ...
I am then trying to add this list of coordinates to the map as markers, in my JavaScript. I am following HERE maps documentation - https://developer.here.com/documentation/examples/maps-js/markers/markers-on-the-map - and trying to loop through each coordinate in my list, creating a new marker for each.
// These variables are dependant on the flask route that is completed
var lat = {{latitude}} // 53.483837
var long = {{longitude}} // -2.225899
var chargepoints = {{chargepoints}}
var coords = {{radius_coordinates}}
// REST OF MAP FUNCTION OMITTED DUE TO LENGTH
// chargepoints = 2 if the chargepoints route is completed
if (chargepoints = 2) {
// ADD THE CHARGEPOINTS TO THE MAP
for (var i=0; i<coords.length; i++) {
var chargemarker = new H.map.Marker({lat:coords[i][1], lng: coords[i][0]}); Cmap.addObject(chargemarker);
Cmap.addObject(chargemarker);
}
}
However when I do this, the map does not load, and I get the error - Uncaught SyntaxError: expected expression, got '&' - in my console, and I don't know where the problem is. When I look in the Web Inspector, the coords variable looks like this.
var coords = ['53.712614', '-1.746287']
print( ... )
in your Python code, especially in the loops. It might show the last line and what the values were. Its been awhile since I worked with Flask, I'm not sure if you can inject aconsole.log(...)
and have it actually output.'
sounds like its the string conversion issue (stackoverflow.com/questions/29314231/…) - those used to be quotes, but your app is translating them to the escaped values. Your "fix" might be as sample as building up your list withfloats
. IE.float(device['ChargeDeviceLocation']['Latitude'])
when makingradius_coordinates
in the Python side of things.