How to determine the city of the visitor?
Your server knows this ip. Depending on which server you have, getting the user's ip may differ.
In nodejs this would be
However, if you don't know how to ask your server ip, you can ask some other server about it.
More servers: https://stackoverflow.com/a/35123097Anonymous
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 incorrectlyAnonymous
To place the code, please use CodePen or similar tool. Thanks you!