我构建了一个使用HTML5函数navigator.geolocation.getCurrentPosition()的HTML页面。
JavaScript将经度、纬度和精度写入屏幕,
但我正在寻找一种方法,将这些数据放入一个文本文件中,然后自动下载到我的计算机(Windows7)中的一个特定目录中,供Python程序稍后读取。你知道吗
<script type="text/javascript">
function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var accuracy = position.coords.accuracy;
document.write("LAT:" + latitude + "_LON:" + longitude+ "_ACU:" + accuracy);
}
function errorHandler(err)
{
var x
switch(error.code)
{
case error.PERMISSION_DENIED:
x = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x = "Location information is unavailable."
break;
case error.TIMEOUT:
x = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x = "An unknown error occurred."
break;
}
document.write(x)
}
function getLocation(){
if(navigator.geolocation){
// timeout at 60000 milliseconds (60 seconds)
var options = {timeout:60000,enableHighAccuracy:true};
navigator.geolocation.getCurrentPosition(showLocation, errorHandler, options);
}
else{
alert("Sorry, browser does not support geolocation!");
}
}
</script>
您需要使提交表单或执行ajax调用。据我所知,这不能用纯javascript在客户端完成。如果您喜欢python,那么可以使用类似these的pythonweb框架
这里的主要问题是客户机和服务器之间的差异。你真的不希望人们能够从你托管的网站向你的计算机写入文件。你知道吗
相关问题 更多 >
编程相关推荐