1

So basically I'm doing google map and I need to add some markers, to do that I need to pass some values I did some research but many of them are executed by pressing a button, I'm really green on Javascript. My python code:

@app.route('/<api_key>')
def main_screen2(api_key=None):
    try:
        api_key = api_key or 'None'
        Reach_sr = Back_End()
        Reach_sr.GetCameras_Info(api_key)
        camera2_title = 'TESTTTaaaazzz'
        camera2_lat = 15.737769
        camera2_log = 40.25693
        return render_template('MAIN_index.html', camera2_title=camera2_title, camera2_lat=camera2_lat, camera2_log=camera2_log )
    except Exception as error:
        print(error) 

And the Javascript code:

function myFunction() {
  var camera2_log = parseFloat("{{ camera2_log }}")
  var camera2_lat = parseFloat("{{ camera2_lat }}")
}

myFunction()

marker2 = new google.maps.Marker({
  map: map,
  draggable: false,
  title: '{{camera2_title}}',
  icon: "https://developers.google.com/maps/documentation/javascript/examples/full/images/info-i_maps.png",
  animation: google.maps.Animation.DROP,
  position: {lat: camera2_lat, lng: camera2_log}
});

The title fits the name correctly, but I have no idea how to also add numbers

2 Answers 2

1

I made a solution to pass a value in a string for example - "5" In the Javascript i did this:

var X1= parseFloat("{{X1_frompython}}", 10);
var X2= parseFloat("{{X2_frompython}}", 10);

This will convert a string into a float, and to access it use - X1, X2

Sign up to request clarification or add additional context in comments.

Comments

0

Surround your variables in double curly brackets so Jinja2 knows to fill them in using the variables passed to render_template, e.g.

position: {lat: {{ camera2_lat }}, lng: {{ camera2_log }}}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.