将变量从python传递给javascript

时间:2014-05-12 12:50:01

标签: javascript python json

我必须要变量 xx = 38.929787 yy = 22.675781

如何在javascript中将它们从python传递给GLatLng(lat,long)并且具有lat = xx和long = yy

def pymapjs(self):
        """ Returns complete javacript for rendering map """

self.js = """\n<script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key=%s\" type="text/javascript"></script>
        <script type="text/javascript">

        //<![CDATA[
        function load() {
            if (GBrowserIsCompatible()) {


            function Point(lat,long,html,icon) {
                  this.gpoint = new GMarker(new GLatLng(lat,long),icon);
                  this.html = html;

               }  

1 个答案:

答案 0 :(得分:1)

这样做:

self.js = """\n<script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key=%s\" type="text/javascript"></script>
    <script type="text/javascript">

    //<![CDATA[
    function load() {
        if (GBrowserIsCompatible()) {


        function Point(lat,long,html,icon) {
              this.gpoint = new GMarker(new GLatLng(%f,%f),icon);
              this.html = html;

           }""" % (xx, yy)