Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Flask Web应用程序(Python 3.6.6)中使用JS地理定位_Javascript_Python_Python 3.x_Flask_Geolocation - Fatal编程技术网

Javascript 在Flask Web应用程序(Python 3.6.6)中使用JS地理定位

Javascript 在Flask Web应用程序(Python 3.6.6)中使用JS地理定位,javascript,python,python-3.x,flask,geolocation,Javascript,Python,Python 3.x,Flask,Geolocation,我正在使用Heroku在Flask中开发一个web应用程序,并试图将纬度和经度数据合并到该应用程序中(我想从login.html文件中获取用户当前的lat/lon,并将其与application.py文件中预先指定的lat/lon进行比较)。我已经编写了代码的JS组件,但我不确定该如何处理它-如何从JS获取地理位置数据并在Flask中使用它?另外,我如何才能看到用户当前的lat/lon 非常感谢您在这方面的任何帮助。 JS代码: {%extends“layout.html”%} {%block

我正在使用Heroku在Flask中开发一个web应用程序,并试图将纬度和经度数据合并到该应用程序中(我想从login.html文件中获取用户当前的lat/lon,并将其与application.py文件中预先指定的lat/lon进行比较)。我已经编写了代码的JS组件,但我不确定该如何处理它-如何从JS获取地理位置数据并在Flask中使用它?另外,我如何才能看到用户当前的lat/lon

非常感谢您在这方面的任何帮助。 JS代码:

{%extends“layout.html”%}
{%block title%}
登录
{%endblock%}
{%block main%}
登录
//使用ajax怎么样?
您可能需要在JS中使用ajax函数。
我为你搜索了所有相关的文章,我想你可以申请。我验证了它的工作原理。希望有帮助:)

{% extends "layout.html" %}

{% block title %}
    Log In
{% endblock %}

{% block main %}
    <form action="/login" method="post">
        <div class="form-group">
            <input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text"/>
        </div>
        <div class="form-group">
            <input class="form-control" name="password" placeholder="Password" type="password"/>
        </div>
        <button class="btn btn-primary" type="submit">Log In</button>
    </form>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script type="text/javascript">// <![CDATA[
        //run this code when the page loads
        jQuery(document).ready(function(){  
            //call the getGeolocation function below
            getGeolocation();
        });  
        //determine if the user's browser has location services enabled. If not, show a message
        function getGeolocation() { 
            if(navigator.geolocation){
                //if location services are turned on, continue and call the getUserCoordinates function below
                 navigator.geolocation.getCurrentPosition(getUserCoodinates);  
            }else{
                alert('You must enable your device\'s location services in order to run this application.');
            }
        }  
        //function is passed a position object which contains the lat and long value
        function getUserCoodinates(position){  
            //set the application's text inputs LAT and LONG = to the user's lat and long position
            jQuery("#LAT").val(position.coords.latitude);
            jQuery("#LONG").val(position.coords.longitude);
        }
    // ]]></script>
{% endblock %}