I have a page on my website that wants to display different content based on the province of the visiting user, so I want to know how to locate the user's province?
The solutions I know about include:
Obtain the latitude and longitude through the front-end geographical location API, and then use the Baidu Map API to check the province;
Directly check the province through the front-end third-party javascript library and pass it to the back-end (should be related to the IP address);
The backend directly obtains the client IP address, and then uses the Taobao IP query interface to find the province;
But every solution has flaws:
Geolocation API may not be supported in IE8, and positioning may be slow;
Through the third-party javascript library, the first request must return a blank page with only the script, and then initiate the request after obtaining the province;
The backend obtains the IP address. If there is a proxy server in the middle, I worry about not getting the real IP. In addition, when testing on localhost, the address obtained is 127.0.0.1, which is inconvenient for testing;
So I want to ask if there is any mature solution?
First display it roughly through geoip to ensure that the first screen loads.
After the front-end side GPS obtains the positioning information, it prompts the user whether to switch to a new city.
Reserve an entrance for users to manually switch cities, and record the user's choice. The user's choice has the highest priority.