[英]html5 geolocation to php variable
How can I get current location from android phone with use HTML5 and assaign it to php variable like $lat and $lon ? 如何使用HTML5从Android手机获取当前位置并将其确定为$ lat和$ lon之类的php变量? I have code like that but how can I use it ?
我有这样的代码,但是我该如何使用呢?
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
var lat = position.coords.latitude;
var lng = position.coords.longitude;
doSomething();
});
}
JavaScript is strictly client-side. JavaScript严格是客户端的。 You'll need to use a postback of some sort - AJAX being the weapon of choice for this.
您将需要使用某种回发-AJAX是为此选择的武器。 From there, store it in whatever session you're using for the user and voila, job done.
从那里,将其存储在您为用户使用的任何会话中,完成任务。
Use AJAX to send the coordinates to a PHP handler function so you can store them anywhere you want (DB, session etc.) and make the handler send the values to your function. 使用AJAX将坐标发送到PHP处理函数,以便可以将它们存储在所需的任何位置(数据库,会话等),并使处理函数将值发送到函数。
I'm suggesting a handler function as that is my style of doing things, but you can send the data to your function directly. 我建议使用处理程序函数,因为这是我的处理方式,但是您可以直接将数据发送到函数。
Also, you can opt for a time triggered event, like let's say send the data every 5 seconds or user event, the sky's the limit from there. 另外,您可以选择一个时间触发的事件,比如说每5秒发送一次数据或用户事件,从那里开始就是天空的极限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.