是否可以根据用户位置更改img? [重复]

This question already has an answer here:

I have a div with an img tag. This img tag should display the visitors country flag. However, im getting no progress in trying to find a solution.

A first thought was maybe those things are possible via server side and php, but then I again there must be a simple jquery method.

I am not asking anyone to code a solution! I just want to know what methods are there for simple tasks like mine? I also tried to look for libraries that do that without the so called "JSON".

</div>

You can do that using the geolocation API. But the user has to allow the location detection for it to work.

https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation

HTML5 provides a Geolocation API, maybe you can try to use that.

https://developers.google.com/maps/documentation/javascript/examples/map-geolocation?hl=de

Google (and maybe other too) offers a free API to transform the location to for example the country.

Unfortunately this is a bit of a link only answer, but you have a similar question here:

Display Country Flag by IP

The answer itself refers to this tutoprial:

http://roshanbh.com.np/2008/07/getting-country-city-name-from-ip-address-in-php.html

This answer also looks very promising:

How can I get user's country flag on my site

According to this link you can also use $_SERVER['HTTP_ACCEPT_LANGUAGE'] to get the language, rather than using a third part service.

Display Flag By Country Script