javascript - How does the website locate the user's province?
过去多啦不再A梦
过去多啦不再A梦 2017-05-18 10:43:56
0
1
461

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:

  1. Obtain the latitude and longitude through the front-end geographical location API, and then use the Baidu Map API to check the province;

  2. 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);

  3. 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:

  1. Geolocation API may not be supported in IE8, and positioning may be slow;

  2. 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;

  3. 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?

过去多啦不再A梦
过去多啦不再A梦

reply all(1)
阿神
  • 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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!