I have seen many forms in which the country field, which by the way is nothing more than a dropdown, and I had the idea of asking them:
How is it done that it is not necessary to select the country where you are located, because it is already selected automatically? What is it made with? How?
With the following code you can do it, in this post it tells us:
To get the user's city you can download:
http://www.maxmind.com/download/geoip/api/php/php-latest.tar.gz
Once you have downloaded the file you will be able to see some examples
examples/city.php
.You will also need to download this file:
and place it in the same directory as your php file.
Source code: https://stackoverflow.com/questions/16702162/php-geo-ip-loc-does-not-work
You can use HTML5 Geolocation and a bit of JavaScript. I do put localization, I add a map, but it depends on your tastes and needs.