0

I wrote a web page that uses javascript to read the user's location including latitude and longitude and finally post that location to a handler in server (to a RazorPage in asp.net core App).

   function getMyLatitude() {
        myLat = 0;


        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (position) {
                myLat = position.coords.latitude;
            })
        }

        return myLat;
    }

This function works correctly.

But some browsers in their desktop version, such as Chrome, have an option by which the user can enter their desired position and from now on, the browser will return the same position as desired by the user.

chrome : developer tools -> settings -> location

chrome : developer tools  -> settings   -> location

Is there a way I can make it so that the user can't manually set their location in the browser, or should I read the user's actual location?

Mehdi
  • 58
  • 7
  • Does this answer your question? [how to detect when user is using mock location chrome browser](https://stackoverflow.com/questions/48085554/how-to-detect-when-user-is-using-mock-location-chrome-browser) – GrafiCode Aug 10 '22 at 10:21
  • It depends on what you will be using the data for. If you really need their accurate location, keep the solution you have. Of course, there would still be potentialities of users on proxies or VPNs. – Sambuxc Aug 10 '22 at 10:29
  • @GrafiCode Thank you, but those articles provided a solution to access location from IP, and location from IP may not be accurate. But using this method, the location of the user is shown almost correctly. – Mehdi Aug 10 '22 at 10:38
  • @SamBrutonDeveloper, That's right, I solved the VPN problem in one way. – Mehdi Aug 10 '22 at 10:41
  • that was a way to double-check user's location. Imagine someone connecting, you get the location (lat, lng) and it says they're from France. Then you geolocate their IP address and it says they're from Brazil. Something's not right, although as @SamBrutonDeveloper noticed, users could connect from VPNs or proxies, so it's not a very reliable method – GrafiCode Aug 10 '22 at 10:42
  • @GrafiCode Thank you for your solution, but the users of my site are salesmens of a broadcasting company and they have to go to different stores in one day according to the schedule. All these stores are in the same city and only a few streets away from each other. Therefore, their IP does not give me specific information, and there is always one IP for them. – Mehdi Aug 10 '22 at 10:49
  • another method, used by some location-based games such as Ingress or Pokemon Go, involves analysing repeated location measurements over the course of time. Imagine a user, their reported location is point X, after 10 minutes their location changes, and it shows point Y, which is like at least 45 minutes away from point X. That means user has "cheated", because there is no way they could move from point X to point Y so quickly. – GrafiCode Aug 10 '22 at 10:56
  • _"the users of my site are salesmens of a broadcasting company and they have to go to different stores in one day according to the schedule"_ - so is the problem that they are using the hardware in place in those stores (and the store owner might have manipulated their location settings on these devices) - or that the salespeople themselves might "cheat", when using their own device? – CBroe Aug 10 '22 at 11:05
  • @GrafiCode It is a creative method. But it doesn't work in this case. The user is supposed to be in a certain place for 4 hours. Without going there, it manually updates its location and then goes to my website. For up to four hours my website reads the same location when he is not there at all and It leaves the site after 4 hours. – Mehdi Aug 10 '22 at 11:13
  • @CBore Yes, they must go to different stores and enter my website through the computers of the same store and register information about the store on the website. In order to understand that they actually went to the desired store, I save the location of each user at the time of registration so that I can compare with the location of the store. – Mehdi Aug 10 '22 at 11:22

0 Answers0