基于 IP 的地理定位

Geolocation based on IP

我正在研究 Angular Google 地图以根据 IP 地址绘制地理位置并使用 ipinfo.io 提供该 IP 地址。

我想知道为什么当我在 ipinfo.io 上获取 IP 地址并使用 Angular Google 地图将其绘制在 google 地图中时,纬度和经度似乎不准确或接近当前位置。


您可以尝试在https://www.whatismyip.com/上获取您当前的IP地址,然后尝试将其放入我的项目中,然后您将看到地理位置。

但我想实现的是这里的输出https://mycurrentlocation.net/index.php

有什么方法可以根据 IP 获得准确的地理位置?


请在 Stackblitz 上查看此实时代码。 https://stackblitz.com/edit/dmgrave-ng-geolocation-by-ip-v1

您正在使用来自 IP 地理定位的坐标 API,与 Wifi 地理定位或 GPS 相比,它的准确性较低。

除非您可以访问最终用户的GPS数据,否则您必须使用第三方服务来转换IP地址或WIFIMAC地址来获取经纬度。

下面有2个方案可以解决您的问题。

1) 要求最终用户通过 HTML 共享他们的 GPS 位置 5. 在这种情况下,网络浏览器将在向您共享坐标之前请求最终用户的授权(视情况而定)。您可以访问 http://ipgeo5.com 获取示例代码。

2) 更改另一个地理位置数据库。如果您关心覆盖范围和准确性,您可以评估其他数据库提供商。您可以访问http://lite.ip2location.com and use their IP2Location LITE database and see if it meet your requirements. If you prefer web API, then you can consider https://www.ipinfodb.com

根据我的研究,我认为这会很好地解释...... 基于 how-can-i-detect-real-location-of-the-user-through-their-ip-address.

Geo-ip location accuracy varies wildly from country to country and from provider to provider. Some smaller countries have very accurate internal mappings of IP's to postal addresses but this type of data is generally not available to the public.

Note: Different Geo-IP address databases may also have different location data for the same IP address so you may also want to double-check the quality of your source data.


我需要使用 HTML5 Geolocation 特别是如果远程设备是具有 GPS 或 GPS 之类的三角测量功能的移动设备,这可能会为您提供比 Geo-IP 地址更准确的信息。

然后

为了能够获得 exact/accurate 位置,用户需要拥有带 GPS 的移动设备,并且用户需要允许 share 他们的位置。

Important Note: Geolocation is most accurate for devices with GPS.


这篇文章(Ip geolocation is almost accurate (reliable), but not 100%)说明了地理定位不准确的原因。

The main reasons for this variation in result is because: 

IP is traced from Provider or organization registration
Use of proxies by the user hides the exact location
Not updated data in the registrar IP database (whois information) 

基于whatismyip

If you lookup your IP address and the city you live in is not shown, but the city 10 miles away where your ISP is located does, then your IP address geolocation data is about as accurate as it's going to get.