search

Home  >  Q&A  >  body text

javascript - How does the website locate the user's province?

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梦2778 days ago536

reply all(1)I'll reply

  • 阿神

    阿神2017-05-18 10:45:56

    • 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.

    reply
    0
  • Cancelreply