PHP 获取移动设备位置?
我想知道是否有办法在 PHP 中从移动设备获取当前位置?我所说的当前位置是指最后已知的位置。
感谢您的帮助!
I am wondering if there is a way to get the current location from a mobile device in PHP? By current location I mean the last known location.
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
HTML5 包含一个可以提供帮助的扩展 JavaScript API,地理定位就是其中之一,问题是某些浏览器不 100% 支持它,Firefox 做得最好。这就是您将如何使用它,之后您将通过 AJAX 将值传递给 PHP。
HTML5 includes an extended JavaScript API that can help, geolocation is one of them, problem is that some browsers do not support it 100%, Firefox doing the best job. This how you would use it, after that you would pass values to PHP via AJAX.
PHP 是一种服务器端脚本语言。它无法访问您的手机。
从手机上运行的 Web 应用程序中,您可以使用 HTML5 地理定位功能在 JavaScript 中获取当前(或最后一个)GPS 位置。但是,不能保证它将使用手机的 GPS 硬件。很多时候我只能从手机信号塔或 WiFi 热点获得结果,精度只有 500 多米左右。
如果您想保证从移动设备的 GPS 硬件获取实际的最后读数,您将需要编写一个移动应用程序来为您访问此信息。
一月份有人问过同样的问题。有关答案的更多详细信息,请参阅这篇文章。
移动 GPS Web 应用程序
PHP is a server side scripting language. It would not have any access to your mobile phone.
From your web application running on the mobilephone, you can use the HTML5 geolocation feature to get your current (or last) GPS location in javascript. BUT, there is no guarantee that it will use the mobile phone's GPS hardware. A lot of times I only get results from cell towers or WiFi hotspots, with accuracy only about 500+ meters.
If you want to guarantee getting the actual last reading from the mobile device's GPS hardware, you will need to write a mobile application to access this information for you.
Someone asked this same question in January. See this article for more detail on answers.
Mobile GPS web application
如果 PHP 与适当的 API 结合来获取移动设备的位置,则可以获取移动位置(粗略)。
http://wiki.opencellid.org/wiki/Main_Page
提供 API 来完成任务但是对于API调用中的参数,我们需要Android设备来这样做。
卷曲这个
http://opencellid.org/cell/get?key=fa83faf1-40d7-XXXX-b97eb197d0bd&mcc=260&mnc=2&lac=10250&cellid=26511&format=json
响应:
{
经: 21.011393650000002,
纬度:52.2308017,
MCC:260,
跨国公司:2,
紫胶:10250,
细胞:26511,
平均信号强度:-65,
范围:34,
样品:2,
可变:真实,
收音机:“GSM”
}
Php can get the mobile location(rough) if it is combined with proper API to get location of the mobile device.
http://wiki.opencellid.org/wiki/Main_Page
provides the API to get things done but for the parameters in API calling we need android device to do so.
cURL this
http://opencellid.org/cell/get?key=fa83faf1-40d7-XXXX-b97eb197d0bd&mcc=260&mnc=2&lac=10250&cellid=26511&format=json
response:
{
lon: 21.011393650000002,
lat: 52.2308017,
mcc: 260,
mnc: 2,
lac: 10250,
cellid: 26511,
averageSignalStrength: -65,
range: 34,
samples: 2,
changeable: true,
radio: "GSM"
}