title: Using JS Geolocation in Flask Web App (Python 3.6.6)
body: <p>I'm working on a web app in Flask using Heroku, and am trying to incorporate latitude and longitude data into the app (I want to take the user's current lat/lon   from my login.html file and compare it to a pre-specified lat/lon in my application.py file). I have the JS component of the code written, but I'm not sure what to do with it - how do I take the geolocation data from JS and use it in Flask? Also, how might I be able to see the user's current lat/lon?</p>
  <p>Any help on this is much, much appreciated.
  JS Code:</p>
  <pre><code>{% extends &quot;layout.html&quot; %}
  
  {% block title %}
      Log In
  {% endblock %}
  
  {% block main %}
      &lt;form action=&quot;/login&quot; method=&quot;post&quot;&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;input autocomplete=&quot;off&quot; autofocus class=&quot;form-control&quot; name=&quot;username&quot; placeholder=&quot;Username&quot; type=&quot;text&quot;/&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;input class=&quot;form-control&quot; name=&quot;password&quot; placeholder=&quot;Password&quot; type=&quot;password&quot;/&gt;
          &lt;/div&gt;
          &lt;button class=&quot;btn btn-primary&quot; type=&quot;submit&quot;&gt;Log In&lt;/button&gt;
      &lt;/form&gt;
      &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;// &lt;![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(&quot;#LAT&quot;).val(position.coords.latitude);
              jQuery(&quot;#LONG&quot;).val(position.coords.longitude);
          }
      // ]]&gt;&lt;/script&gt;
  {% endblock %}
  </code></pre>