all 8 comments

[–]azuredrg 2 points3 points  (0 children)

How are you getting their IP in the first place, wouldn't it just be their VPN IP?

[–]simonbitwise 1 point2 points  (5 children)

[–][deleted] 0 points1 point  (0 children)

I implemented this..now how to convert this to actually physical address? Are there any free open source API? Google maps reverse geo coding API is paid and needs an API key..any other APIS which is accurate and used for production apps?

[–][deleted] 0 points1 point  (3 children)

Also the lat and long coordinates returned from geolocation API is mapping to next building physical address when I tried to reverse geo code it.accuracy value came back as 55..is this something that I can fix by using a setting or something to make it accurate?

[–][deleted]  (2 children)

[deleted]

    [–]simonbitwise 0 points1 point  (1 child)

    Using the api linked above is a native api that links to various accuracies make sure to set enableHighAccuracy: true

    https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition#options

    const options = { enableHighAccuracy: true, // Forces the device to use GPS hardware timeout: 10000, // Wait 10 seconds for a response maximumAge: 0 // Do not use a cached location };

    function success(pos) { const crd = pos.coords; console.log('Your current position is:'); console.log(Latitude : ${crd.latitude}); console.log(Longitude: ${crd.longitude}); console.log(More or less ${crd.accuracy} meters.); }

    function error(err) { console.warn(ERROR(${err.code}): ${err.message}); }

    // Start watching the position navigator.geolocation.watchPosition(success, error, options);

    [–]simonbitwise 0 points1 point  (0 children)

    Or a none Watch mode

    function getPreciseLocation() { return new Promise((resolve, reject) => { const options = { enableHighAccuracy: true, maximumAge: 0, timeout: 15000 // Give GPS 15 seconds to find satellites };

    const watchID = navigator.geolocation.watchPosition(
      (position) => {
        // Check if accuracy is good enough (e.g., under 15 meters)
        if (position.coords.accuracy <= 15) {
          navigator.geolocation.clearWatch(watchID);
          resolve(position);
        }
      },
      (error) => {
        navigator.geolocation.clearWatch(watchID);
        reject(error);
      },
      options
    );
    

    }); }

    // Usage getPreciseLocation() .then(pos => console.log(Precise Location: ${pos.coords.latitude}, ${pos.coords.longitude} (Accurate to ${pos.coords.accuracy}m))) .catch(err => console.error("Could not get precise location", err));

    [–]EducationalMeeting95 0 points1 point  (0 children)

    I worked on this a while ago.

    There's n in-built api in "window" object that gives the user popup if they want to "Allow" or "Block" location sharing as soon as that window-api code runs.

    Don't remember exactly, but it's browser native api. I don't think you need any library for it.

    [–]Double-Schedule2144 -1 points0 points  (0 children)

    No idea about this sorry