我正在尝试将“纬度”和“经度”值写入保存在我的服务器
中的txt文件我的代码是
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<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>
<script>
getLocation();
</script>
<?php
$handle = fopen("location", "a");
foreach ( $_GET as $key => $value )
{
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
fclose($handle);
exit;
?>
</body>
</html>
访问html页面后,每次都会得到一个空白文本文件 我希望“position.coords.latitude”和position.coords.longitude写在txt文件中