【发布时间】:2015-07-14 13:32:34
【问题描述】:
我有这段代码,它显示地理位置(经度:xx 纬度:xx 精度:xxx)..当任何人访问 url 时,我如何将结果输出到日志文件 log.txt
<!-- <xml version="1.0" encoding="utf-8"> -->
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Geolocation API Demo</title>
<meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" name="viewport"/>
<script>
function successHandler(location) {
var message = document.getElementById("message"), html = [];
html.push("<img width='512' height='512' src='http://maps.google.com/maps/api/staticmap?center=", location.coords.latitude, ",", location.coords.longitude, "&markers=size:small|color:blue|", location.coords.latitude, ",", location.coords.longitude, "&zoom=16&size=512x512&sensor=false' />");
html.push("<p>Longitude: ", location.coords.longitude, "</p>");
html.push("<p>Latitude: ", location.coords.latitude, "</p>");
html.push("<p>Accuracy: ", location.coords.accuracy, " meters</p>");
message.innerHTML = html.join("");
}
function errorHandler(error) {
alert('Attempt to get location failed: ' + error.message);
}
navigator.geolocation.getCurrentPosition(successHandler, errorHandler);
</script>
</head>
<body>
<div id="message">Location unknown</div>
</body>
</html>
【问题讨论】:
-
你想用java还是php导出。
-
您必须在服务器端执行此操作,将对象发送到服务器并使用它做任何您想做的事情。 JS 无权访问客户端/服务器文件系统
-
是否要将所有用户的结果附加到同一个文件中?无法通过客户端保存文件。
-
我想使用 php @Satya 导出
-
不,我想将结果附加到单独的文件 log.txt @NishantGhodke
标签: javascript php html geolocation