![](/img/trans.png)
[英]Creating lines using google maps api with coordinates from database javascript MySQL PHP
[英]Send current gps coordinates to mySQL database using google maps api
我正在嘗試在 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>
此代碼顯示當前位置,但必須有一個請求 function 可以將 position.coords.latitude+","+position.coords.longitude 發送到數據庫?
我真的不確定你想做什么,但這里有一些文章在谷歌地圖 API 網站上使用 PHP 和 MySQL 與谷歌地圖 API:
https://developers.google.com/maps/articles/phpsqlsearch_v3
https://developers.google.com/maps/articles/phpsqlajax_v3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.