How to determine the city of the visitor?

  • 0
    DD, please tell me how to determine the city of the visitor who entered the page, found dadata's ip search, but I don't know how to find out the ip of the user who visited the page, help me!
    JavaScript Adam Collier, Dec 10, 2019

  • 2 Answers
  • 0
    Your server knows this ip. Depending on which server you have, getting the user's ip may differ.



    In nodejs this would be request.connection.remoteAddress , eg.



    However, if you don't know how to ask your server ip, you can ask some other server about it.

    Example: https://codepen.io/stalker-red/pen/WNrPEEK

    More servers: https://stackoverflow.com/a/35123097
    Anonymous

  • 0
    What if the user uses a VPN?

    How do you like the percentage of false positives?

    It would be more correct to ask the user for geolocation explicitly.

    https://developer.mozilla.org/en/docs/Web/API / Geol ...

    And using the data received from, for example, a Google API by location, pull the city, plus allow the user to select the city from here if he has defined it incorrectly
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!