Привет!Мне нужна помощь!Можно ли загрузить местоположение (геолокация HTML5), не открывая браузер?Например, переписав код HTML5 и JS с помощью js2py? file main.py:
import js2py
js2py.eval_js("Content-type: text/html\n\n")
js2py.eval_js("""\
<html>
<head>
<p id="demo">Test:</p>
<script>
var x=document.getElementById("demo");
function getLocation()
{
//this is to send the location back to your python script
var req = new XMLHttpRequest();
req.open('GET', 'location.py?lat=1&lon=2', false);
req.send(null);
//----------------------------------------------
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;
}
window.onload = getLocation;
</script>
</head>
<body>
</body>
</html>""")
и файла location.py:
import cgi
form = cgi.FieldStorage()
lat = form.getvalue('lat')
lon = form.getvalue('lon')
with open('location.txt', 'wt') as f:
if lat:
f.write(lat)
f.write("\n")
if lon:
f.write(lon)
f.close()
Я играю, но не могу.Мне нужна эта функция для моего проекта в школу.