Javascript 如何将HTML5、纬度和经度保存到数据库中?
我需要将纬度和经度保存到我的数据库中。我可以得到坐标值,但我不能将它们分配给PHP变量,以便将它们插入数据库。我看了很多youtube视频,读了很多博客,但其中的一个都在工作。我不知道哪种方法更适合在数据库中插入坐标,请指导我,谢谢 以下是我的代码:Javascript 如何将HTML5、纬度和经度保存到数据库中?,javascript,php,jquery,ajax,html,Javascript,Php,Jquery,Ajax,Html,我需要将纬度和经度保存到我的数据库中。我可以得到坐标值,但我不能将它们分配给PHP变量,以便将它们插入数据库。我看了很多youtube视频,读了很多博客,但其中的一个都在工作。我不知道哪种方法更适合在数据库中插入坐标,请指导我,谢谢 以下是我的代码: <body> <p>HTML5 GEOLOCATION</p> <a href="#" id="get_location">Get Location</a> &l
<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>
只需使用jQuery对服务器端语言(即PHP)进行ajax调用,并将lat&lang参数传递到PHP页面
$.ajax({
type: 'POST',
url: 'your_server_url.php',
async:true,
data: {
'lat': lat,
'lang': lang
},
success: function(response){
// alert('wow' + msg);
}
});
在php页面中读取如下参数
$lat = $_POST['lat'];
$lang = $_POST['lang'];
//your database logic
好啊如何使用ajax?有任何教程链接吗?我只是发布了答案。这解决了你的问题吗?如果被否决,请提供评论。谢谢,但没有工作,兄弟。这个网站有限制,我不能问每一个问题,我们可以通过电子邮件聊天吗?danijami45@aol.commail把你的问题告诉我amoltate@yopmail.comi我真的很抱歉迟到了。我已经在您的电子邮件地址上向您发送了一封电子邮件,请结帐。请先生查看您的电子邮件地址,我已经向您发送了一封电子邮件。