【问题标题】:I want to change the content of website depending on location [duplicate]我想根据位置更改网站的内容[重复]
【发布时间】:2021-08-01 17:27:47
【问题描述】:

我想根据用户的位置更改我网站的内容。我想知道用 js 实现这个的方法是什么。 我有这个附属网站www.goshaheen.com,我只是想如果有人在不同的国家打开看到不同的结果。谢谢

【问题讨论】:

    标签: javascript


    【解决方案1】:

    您需要使用 https://ipstack.com/ 等外部 API 来帮助您根据 IP 地址检测国家(您可以根据用户的 GPS 位置定位用户,但大多数用户拒绝在浏览器中这样做)。当您使用他们的 (https://ipstack.com/) API 并获取国家/地区时,您可以重定向到新链接,例如 www.goshaheen.com/uk(适用于英国)。

    API Provider 有很多,我提到的这个提供 5000 个请求/月免费。

    你会得到这样的回应:

    {
      "ip": "134.201.250.155",
      "hostname": "134.201.250.155",
      "type": "ipv4",
      "continent_code": "NA",
      "continent_name": "North America",
      "country_code": "US",
      "country_name": "United States",
      "region_code": "CA",
      "region_name": "California",
      "city": "Los Angeles",
      "zip": "90013",
      "latitude": 34.0453,
      "longitude": -118.2413,
      "location": {
        "geoname_id": 5368361,
        "capital": "Washington D.C.",
        "languages": [
            {
              "code": "en",
              "name": "English",
              "native": "English"
            }
        ],
        "country_flag": "https://assets.ipstack.com/images/assets/flags_svg/us.svg",
        "country_flag_emoji": "??",
        "country_flag_emoji_unicode": "U+1F1FA U+1F1F8",
        "calling_code": "1",
        "is_eu": false
      },
      "time_zone": {
        "id": "America/Los_Angeles",
        "current_time": "2018-03-29T07:35:08-07:00",
        "gmt_offset": -25200,
        "code": "PDT",
        "is_daylight_saving": true
      },
      "currency": {
        "code": "USD",
        "name": "US Dollar",
        "plural": "US dollars",
        "symbol": "$",
        "symbol_native": "$"
      },
      "connection": {
        "asn": 25876,
        "isp": "Los Angeles Department of Water & Power"
      },
      "security": {
        "is_proxy": false,
        "proxy_type": null,
        "is_crawler": false,
        "crawler_name": null,
        "crawler_type": null,
        "is_tor": false,
        "threat_level": "low",
        "threat_types": null
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-09
      相关资源
      最近更新 更多