有没有好的 PHP 地理定位服务? [英] is there a good PHP geolocation service?

查看:17
本文介绍了有没有好的 PHP 地理定位服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个好的 PHP 地理定位服务,所以当我启动我的应用程序时,我可以得到类似的东西:

i am looking for a good PHP geolocation service, so when i start my app i can have something like:

<?php
$service = new GeoLocService();
echo $service->getLat();
echo $service->getLng();
?>

以纬度和经度值检索用户的位置.

to retrieve the position of the user in latitude and logitude values.

推荐答案

地理定位需要在浏览器中完成,因为服务器(即 PHP)永远无法找到大部分相关数据.在浏览器中进行地理定位的主要 API 是 Google 的,但作为开发人员的您不需要使用该 API;您将使用浏览器的标准化 API(尽管目前仅在少数浏览器中受支持).

Geo-location would need to be done in the browser, since the server (ie PHP) would never get to find out most of the relevant data. The main API for doing geolocation in the browser is Google's, but you as a developer wouldn't need to use that API; you'd use the browser's API, which is standardised (though only supported in a few browsers so far).

用于在服务器端定位用户的最有用信息是他们的 IP 地址,这通常足以将他们定位到最近的城镇.您可以下载 IP 到国家和 IP 到位置的数据库和 API,以帮助解决此问题.有些是免费的,但要获得城镇级别的位置,您需要为服务付费.无论您选择哪种方式,它们都需要保持最新状态,因为 IP 范围通常会重新分配.

The most useful information you'll get for locating a user at the server end would be their IP address, which is often sufficient to locate them down to the nearest town. There are IP-to-nation and IP-to-location databases and APIs which you can download to help with this. Some are free, but to get the town-level locations, you'll be paying for the service. Whichever you go with, they do need to be kept up-to-date though, because IP ranges are often re-allocated.

浏览器级 API 的工作原理是让浏览器扫描 Wi-Fi 接入点区域.它将接入点列表发送给 Google,然后 Google 使用该列表来计算纬度/经度(通常会得出惊人的准确结果).

The browser-level APIs work by having the browser scan the area for Wi-Fi access points. It sends the list of access points to Google, who then use that to work out the Lat/Long (often with alarmingly accurate results).

他们是怎么做到的?您可能还记得谷歌最近因为从人们的 Wi-Fi 获取数据而陷入困境吗?他们实际上试图做的是为这个地理定位功能绘制全球 Wi-Fi 接入点的地图.

How do they do that? You may remember Google getting into trouble recently for sucking data from people's Wi-Fis? What they were actually trying to do was map the world's Wi-Fi access points for this geolocation feature.

当然,它确实需要客户端启用 Wi-Fi.

It does, of course, require the client to have Wi-Fi enabled.

请注意,您的浏览器不会直接访问此访问点列表到客户端(即 Javascript 或 DOM),因此您无法将其发布到 PHP 以通过服务器使用此方法获取位置;它必须在客户端完成.

Note that your browser doesn't give direct access to this list of access points to the client (ie Javascript or the DOM), so you can't post it to PHP to get the location using this method via the server; it would have to be done at the client-end.

这篇关于有没有好的 PHP 地理定位服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆