我正在尝试在jquery中构建一个高尔夫应用程序,我可以使用按钮将当前的gps坐标发送到mySQL数据库。
问题是我是php的新手,我正在尝试找到可以使用的代码。 我已经建立了一个数据库:
有人可以帮忙解决一些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发送到数据库?
答案 0 :(得分:1)
我真的不确定你要做什么,但是Google Maps API网站上有一些关于使用PHP和MySQL以及Google Maps API的文章:
https://developers.google.com/maps/articles/phpsqlsearch_v3
https://developers.google.com/maps/articles/phpsqlajax_v3