vendredi 28 juillet 2017

How to send the value of a python variable to javascript in html

Good morning. I am using the google app engine to display a google map on a web page.

I want to bring the latitude and longitude in the database and display it on the map. To do this, I need to pass the imported latitude and longitude to javascript in html. I have tried several ways but it is useless. ( ex. is useless) help me please. High Programmers i need you!!help me help me

class Map(webapp2.RequestHandler):

    db = connect_to_cloudsql()
    cursor = db.cursor()
    cursor.execute("""select latitude,longitude from User;""")

    data=cursor.fetchone() 
    lat=data[0]
    lng=data[1]

    formstring = """
    <!DOCTYPE html> 
    <html lang="ko-KR">
    <head>
    <meta charset="utf-8"/>
        <meta name="google-site-verification" content="9EqLgIzCmwFo7XAcSe4sBNZ_t0gULadyeF9BCO0DY3k"/>
    </head>
    <body class>
    <style>
     #map {
        width: 80%;
        height: 400px;
        background-color: grey;
      }
    </style>
    <div style="position:relative;width:1080px;margin:0 auto;z-index:11">
    <div class="container" role="main">
    <h3>{lat}</h3>
    <div id="map"></div>
    <br><br>
    <script async defer
    src="http://ift.tt/2ve4vPA">
    </script>

    <script>
      $.get(getLocation,function(data){
        var location=data;
      })
      function initMap() {

        var uluru = {lat: {lat} , lng: {lng} };
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 4,
          center: uluru
        });
        var marker = new google.maps.Marker({
          position: uluru,
          map: map
        });
      }
    </script>

    </div>
    </div>
    </body>
    </html>
        """




Aucun commentaire:

Enregistrer un commentaire