我正在尝试在 jquery 中构建一个高尔夫应用程序,我可以使用按钮将当前 gps 坐标发送到 mySQL 数据库。
问题是我是 php 新手,我正在尝试找到我可以使用的代码。我建立了一个数据库:
- ID int 3 自增
- 纬度浮动 10
- LON 浮点数 10
有人可以帮助一些html和php代码吗?
<!DOCTYPE html>
<html>
<body>
<div data-role="page" id="page1">
<div data-theme="b" data-role="header" data-position="fixed">
<h5>
Play 9 holes
</h5>
</div>
</div>
<p id="demo">Click the button to get your position:</p>
<button onclick="getLocation()">Try It</button>
<div id="mapholder"></div>
<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function showPosition(position)
{
var latlon=position.coords.latitude+","+position.coords.longitude;
var img_url="http://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&zoom=14&size=400x400&sensor=false";
document.getElementById("mapholder").innerHTML="<img src='"+img_url+"' />";
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML="The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="An unknown error occurred."
break;
}
}
</script>
</body>
</html>
此代码显示当前位置,但必须有一个请求函数可以将 position.coords.latitude+","+position.coords.longitude 发送到数据库?