我需要將緯度和經度保存到我的數據庫中。我可以獲取座標值,但是我不能將它們分配給PHP變量,以便我可以將它們插入到數據庫中。我觀看過很多YouTube視頻並閱讀了很多博客,但他們的尼姑工作過。我不知道哪種方式更好地將座標插入數據庫,請指導我,謝謝。如何將HTML5,經緯度保存到數據庫中?
以下是我的代碼:
<body>
<p>HTML5 GEOLOCATION</p>
<a href="#" id="get_location">Get Location</a>
<div id="map">
<iframe id="google_map" width="425" height="350" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/view?zoom=9¢er=24.8615,67.0099&key=AIzaSyAgiV9XkktBAHcfc1XIkLcUngBuSnxmk1o"></iframe>
</div>
<script>
var c = function(pos){
var lat = pos.coords.latitude,
long = pos.coords.longitude,
coords = lat +', '+long;
document.getElementById('google_map').setAttribute('src','https://maps.google.co.uk/?q='+ coords +'&z=15&output=embed');
alert("latitude= "+lat+"\nlongitude= "+long);
}//end of function c
document.getElementById('get_location').onclick = function(){
navigator.geolocation.getCurrentPosition(c);
return false;
}//end of document.getElementById()
</script>
</body>
改爲使用Ajax。 – Amy 2014-10-31 06:45:41
好的。我如何使用Ajax?有任何教程鏈接? – 2014-10-31 09:03:53
我只是發佈答案提到這個 – Amy 2014-10-31 10:05:45