Search code examples
angulargoogle-mapsgeoipangular-google-maps

Geolocation based on IP


I am working on Angular Google Maps to plot the geolocation based on IP address and using ipinfo.io to provide that IP address.

I would like to know why when I get the IP address on ipinfo.io and plot it in google maps using Angular Google Maps, the lat and long seems not accurate or somehow close to the current location.


You can try to get your current IP address on https://www.whatismyip.com/ and then try to put it in my project then you will see the geolocation.

but what I wanted to achieve is the output here https://mycurrentlocation.net/index.php

Is there a way that I can get an accurate geolocation based on IP?


Please see this live code on Stackblitz. https://stackblitz.com/edit/dmgrave-ng-geolocation-by-ip-v1


Solution

  • Based on my research I think this will explain well.. Based on 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.


    I need to use HTML5 Geolocation especially if the remote device is a mobile device with GPS or GPS like triangulation features this may give you much more accurate info than the Geo-IP address.

    and then

    To be able to get the exact/accurate location is that the user need to have a mobile device with GPS and the user need to allow to share their location.

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


    This article (Ip geolocation is almost accurate (reliable), but not 100%) shows the reason why geolocation is not accurate.

    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) 
    

    Based on 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.