An easy way is with GeoLite (http://dev.maxmind.com/geoip/legacy/geolite/). Because it uses a local database no web service calls are needed and it's much faster for geocoding large numbers of IPs.
Basically, what Firefox 3.5 (as well as Chrome) does is to get the list of nearby Wi-Fi networks and send that list using JSON to a Google webservice, which will then return the approximate coordinates.
By the way, there is no Java involved in this process. To get geolocation from Firefox/Chrome, you just call a few JavaScript methods. (I really hope that you know that Java is different from JavaScript)
发布评论
评论(2)
一个简单的方法是使用 GeoLite (http://dev.maxmind.com/geoip/legacy/geolite /)。由于它使用本地数据库,因此不需要 Web 服务调用,并且对大量 IP 进行地理编码的速度要快得多。
操作方法如下:
添加此 Maven 工件:
从 http 下载地理位置数据文件: //geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
将文件解压到任意文件夹中。然后执行以下操作:
结果将位于 Location 对象中的纬度、经度、城市、地区和国家代码属性中。
请查看他们的精度估计,以确保其满足您的项目的需求:http://www.maxmind .com/en/geolite_city_accuracy。
An easy way is with GeoLite (http://dev.maxmind.com/geoip/legacy/geolite/). Because it uses a local database no web service calls are needed and it's much faster for geocoding large numbers of IPs.
Here is how:
Add this Maven artifact:
Download the geolocation data file from http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
Unpack the file into any folder. Then do:
The result will be in the Location object in the latitude, longitude, city, region and countryCode properties.
Please take a look at their accuracy estimates to ensure it meets the needs of your project: http://www.maxmind.com/en/geolite_city_accuracy .
如果您想知道 Firefox 3.5(或 Google Chrome)如何获取地理位置,请查看此处:Google/Firefox Geolocation API 的工作原理
基本上,Firefox 3.5(如Chrome)所做的就是获取附近 Wi-Fi 网络的列表,并使用 JSON 将该列表发送到 Google Web 服务,然后 Google Web 服务将返回大致坐标。
顺便说一下,这个过程没有Java的参与。要从 Firefox/Chrome 获取地理位置,您只需调用一些 JavaScript 方法。 (我真的希望你知道 Java 与 JavaScript 不同)
If you want to know how Firefox 3.5 (or Google Chrome) gets the geolocation, then please take a look here: How Google/Firefox Geolocation API works
Basically, what Firefox 3.5 (as well as Chrome) does is to get the list of nearby Wi-Fi networks and send that list using JSON to a Google webservice, which will then return the approximate coordinates.
By the way, there is no Java involved in this process. To get geolocation from Firefox/Chrome, you just call a few JavaScript methods. (I really hope that you know that Java is different from JavaScript)