【问题标题】:How could I store the variables better?我怎样才能更好地存储变量?
【发布时间】:2013-01-13 05:32:12
【问题描述】:

这是我小组的项目:https://github.com/stuycs-ml7-projects/YAN-SHAN-PHAN-WU

我们正在开发可以使用 GPS 将消息存储在位置的应用程序(一个网站)。消息只能在其特定坐标处访问和存储。

我会经历我所拥有的。

HTML 初始化变量

<input type="hidden" id="Latitude" name="Latitude">
<input type="hidden" id="Longitude" name="Longitude">

我使用 document.ready 函数调用 getLocation() 将它们存储在隐藏字段中。

function getLocation()
  {if (navigator.geolocation)
    {    navigator.geolocation.watchPosition(showPosition);     }
  }
function showPosition(position)
  {
      document.getElementById("Latitude")  =  position.coords.latitude;
      document.getElementById("Longitude") =  position.coords.longitude;
  }

$(document).ready(function() {
   getLocation();
});

如果我按下一个按钮,它将请求 app.py 中的数据

Latitude = request.form['Latitude']
Longitude = request.form['Longitude']

然后找到该位置的所有消息

messages = database.returnMessagesinRange(Latitude,Longitude)
            return render_template('SCAN.html',messages=messages,
                Latitude =   Latitude, Longitude = Longitude)

沿线某处,我丢失了坐标并最终得到空白变量。有任何解决方法的想法,或者可能是避免所有麻烦的捷径吗?

【问题讨论】:

    标签: javascript python html geolocation


    【解决方案1】:

    这是一个快速的猜测,但尝试将 document.getElementById("Latitude") = ... 替换为 document.getElementById("Latitude").value = ...

    【讨论】:

    • 还有几个错误,但这真的很有帮助,我从来没想过要寻找这个
    • 很高兴它有帮助!在学习这些东西时,真正对我有用的一件事是 Gecko Dom 参考 (developer.mozilla.org/en-US/docs/Gecko_DOM_Reference)。它有点密集,但非常详尽。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 2020-04-06
    • 2021-01-31
    • 2013-09-28
    • 1970-01-01
    • 2023-02-13
    • 1970-01-01
    相关资源
    最近更新 更多