我需要将纬度和经度保存到我的数据库中。我可以获取坐标值,但是我不能将它们分配给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