简体   繁体   中英

how can i pass these javascript variables i.e coordinates to my flask

I am not able to pass the coordinates to my flask

i have no idea how to pass javascript variables

<script>
var x = document.getElementById("demo");

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude;
}
</script>

Latitude: 13.8863984 Longitude: 77.44150069999999

Depending on what you are trying to achieve, you might want to use AJAX to send data to flask. This would be useful if you wanted to process the latitude and longitude data in flask and do something with it. Here is a link to another StackOverflow question which contains info on how to do this: How to send data to Flask via AJAX?

Use geocoder instead, it is realy simple.

import geocoder as gc
g = gc.ip('me') #ip is also accepted here
print(g.latlng)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM