使用Google Maps API将当前GPS坐标发送到mySQL数据库 [英] Send current gps coordinates to mySQL database using google maps api
问题描述
我试图在jQuery中构建一个高尔夫应用程序,我可以使用按钮将当前gps坐标发送到mySQL数据库。
问题是,我是PHP的新手,我试图找到可以使用的代码。
我建立了一个数据库:
- ID int 3 autoincrement
- LAT float 10
- LON float 10
有人可以帮助使用一些html和php代码吗? p>
<!DOCTYPE html>
< html>
< body>
< div data-role =pageid =page1>
< div data-theme =bdata-role =headerdata-position =fixed>
< h5>
播放9个洞
< / h5>
< / div>
< / div>
< p id =demo>点击按钮以获取您的位置:< / p>
< button onclick =getLocation()>试试< / button>
< div id =mapholder>< / div>
< script>
var x = document.getElementById(demo);
函数getLocation()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition,showError);
else {x.innerHTML =此浏览器不支持地理定位。;}
}
函数showPosition(位置)
{
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 =假;
document.getElementById(mapholder)。innerHTML =< img src ='+ img_url +'/>;
函数showError(错误)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML =用户拒绝地理定位请求。
休息;
case error.POSITION_UNAVAILABLE:
x.innerHTML =位置信息不可用。
休息;
case error.TIMEOUT:
x.innerHTML =请求获取用户位置超时。
休息;
case error.UNKNOWN_ERROR:
x.innerHTML =发生未知错误。
休息;
}
}
< / script>
< / body>
< / html>
此代码显示当前位置,但必须有可发送position.coords.latitude + ,+ position.coords.longitude to database?
我真的不确定你要做什么,但以下是Google Maps API网站中有关使用PHP和MySQL以及Google Maps API的文章: https://developers.google.com/maps/articles/phpsqlsearch_v3
https://developers.google.com/maps/articles/ phpsqlinfo_v3
https:/ / DEVE lopers.google.com/maps/articles/phpsqlgeocode
I am trying to build a golf app in jquery where I can send the current gps coordinates to a mySQL database using a button.
The problem is that I am new to php and I am trying to find code that i can use. I have built a database:
- ID int 3 autoincrement
- LAT float 10
- LON float 10
Can someone please help with some html and php code?
<!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>
this code shows current location but there has to be a request function that can send position.coords.latitude+","+position.coords.longitude to database?
I'm really not sure what you're trying to do, but here's some articles in the Google Maps API site on using PHP and MySQL with the Google Maps API:
https://developers.google.com/maps/articles/phpsqlsearch_v3
https://developers.google.com/maps/articles/phpsqlajax_v3
https://developers.google.com/maps/articles/phpsqlinfo_v3
https://developers.google.com/maps/articles/phpsqlgeocode
这篇关于使用Google Maps API将当前GPS坐标发送到mySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!