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

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

问题描述

我正在寻找一个好的PHP地理定位服务,所以当我开始我的应用程序时,我可以有这样的东西:

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

检索用户在纬度和经度值上的位置。


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



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

浏览器级别的API通过让浏览器会扫描该区域的Wi-Fi接入点。它将访问点列表发送给Google,然后用它来计算Lat / Long(通常具有令人惊讶的准确结果)。

他们如何做到这一点?您可能还记得最近因为从人们的Wi-Fi吸取数据而陷入困境吗?他们实际上试图做的是映射全球的Wi-Fi接入点来实现这种地理定位功能。



当然,它确实需要客户端拥有Wi-Fi请注意,您的浏览器不能直接访问此客户端访问点列表(即Javascript或DOM),因此您无法发布它通过服务器使用这种方法来获取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.

解决方案

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).

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.

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).

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.

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

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天全站免登陆