开源api_开源IP地理位置API

本文介绍了开源的IP Geolocation API,这是一个免费的地理位置服务,用于确定互联网设备的位置。它允许用户从IP地址获取位置数据,提供语言定制、安全层等功能。文章详细阐述了API的工作原理、如何部署独立版本以及如何使用HTTP端点来获取信息。
摘要由CSDN通过智能技术生成

开源api

Geo-location is the identification or estimation of the real-world geographic location of an Internet-connected computer terminal or device.

地理位置是对互联网连接的计算机终端或设备的真实地理位置的标识或估计。

Basically, we can get location data from their IP address.

基本上,我们可以从其IP地址获取位置数据。

Geo-location offers a lot of advantages and increase level of customization to a website. We can:

地理位置提供了很多优势,并提高了网站的自定义级别。 我们可以:

  • Give users data in their language.

    向用户提供其语言的数据。
  • With knowlege of cultural differences, properly represent data.

    具有文化差异的知识,可以正确地代表数据。
  • Build a security layer/firewall

    建立安全层/防火墙

and many, many more features.

还有很多其他功能

If you do a Google search, there are many services that offer Geo-location for a price. Or, companies like MaxMind that offer a subset of the data they’ve gathered over the years for free.

如果您进行Google搜索,则有许多服务可以按价格提供地理位置。 或者,像MaxMind这样的公司免费提供了这些年来收集的部分数据。

With companies like MaxMind, you have to download their database every now and then to make sure the data is up to date, manage your own servers, and all other house-keeping. That’s what IP Geolocation API will do for you.

对于像MaxMind这样的公司,您必须不时下载其数据库,以确保数据是最新的,管理自己的服务器以及所有其他整理工作。 这就是IP Geolocation API会为您做的。

什么是IP地理位置API及其如何工作 ( What is IP Geolocation API and How Does it Work )

IP Geolocation API, is a free to use Geo-location service.

IP Geolocation API ,是免费使用的Geo-location服务。

The code is open-source which means you can deploy your version of the product and let it run all the house keeping for you. It is written in Python. So, if you need to fork and modify, you probably need to know how to code in Python.

该代码是开源的 ,这意味着您可以部署产品的版本,并让它为您管理所有事务。 它是用Python编写的。 因此,如果您需要进行派生和修改,则可能需要了解如何使用Python进行编码。

When a request comes into the application,

当请求进入应用程序时,

如何部署独立版本 ( How to Deploy a Standalone Version )

Heroku is probably the best option since it’s managed.. If you already use Heroku, you can do a quick deploy by clicking this link.

Heroku可能是最好的选择,因为它已经被管理。如果您已经在使用Heroku,则可以通过单击此链接进行快速部署。

Another reason to use heroku is that whenever the database gets updated, deployment is very easy.

使用heroku的另一个原因是,每当数据库更新时,部署都很容易。

使用API ( Using the API )

Currently, the API has four HTTP endpoints. **Don’t leave the slash at the end of the URL**.

目前,API有四个HTTP端点。 **不要在网址末尾加斜杠**。

GET https://api.ipgeolocationapi.com/geolocate HTTP/1.1
GET https://api.ipgeolocationapi.com/geolocate/<ip> HTTP/1.1
GET https://api.ipgeolocationapi.com/countries HTTP/1.1
GET https://api.ipgeolocationapi.com/countries/<country_code> HTTP/1.1
  • /geolocate will automatically detect the users IP address and return the location data.

    /geolocate将自动检测用户的IP地址并返回位置数据。

  • /geolocate/<ip> requires you to supply the users IP address and returns the same data as /geolocate

    /geolocate/<ip>要求您提供用户IP地址并返回与/geolocate相同的数据

  • /countries returns a list of the countries in the database and all the information they have about them.

    /countries返回数据库中的国家/countries列表,以及有关它们的所有信息。

  • /countries/<country_code> returns the information about one country.

    /countries/<country_code>返回有关一个国家的信息。

Note: If you deployed your own version, you’ll want to replace _https://api.ipgeolocationapi.com with your own domain_

注意:如果您部署了自己的版本,则需要将_ https://api.ipgeolocationapi.com替换为您自己的domain_

Making a request to https://api.ipgeolocationapi.com/geolocate will give you:

https://api.ipgeolocationapi.com/geolocate发出请求将为您提供:

{
       "continent":"Europe",
       "address_format":"{{recipient}}\n{{street}}\n{{postalcode}} {{city}}\n{{country}}",
       "alpha2":"DE",
       "alpha3":"DEU",
       "country_code":"49",
       "international_prefix":"00",
       "ioc":"GER",
       "gec":"GM",
       "name":"Germany",
       "national_destination_code_lengths":[
          2,
          3,
          4,
          5
       ],
       "national_number_lengths":[
          6,
          7,
          8,
          9,
          10,
          11
       ],
       "national_prefix":"0",
       "number":"276",
       "region":"Europe",
       "subregion":"Western Europe",
       "world_region":"EMEA",
       "un_locode":"DE",
       "nationality":"German",
       "eu_member":true,
       "eea_member":true,
       "vat_rates":{
          "standard":19,
          "reduced":[
             7
          ],
          "super_reduced":null,
          "parking":null
       },
       "postal_code":true,
       "unofficial_names":[
          "Germany",
          "Deutschland",
          "Allemagne",
          "Alemania",
          "ドイツ",
          "Duitsland"
       ],
       "languages_official":[
          "de"
       ],
       "languages_spoken":[
          "de"
       ],
       "geo":{
          "latitude":51.165691,
          "latitude_dec":"51.20246505737305",
          "longitude":10.451526,
          "longitude_dec":"10.382203102111816",
          "max_latitude":55.0815,
          "max_longitude":15.0418962,
          "min_latitude":47.2701115,
          "min_longitude":5.8663425,
          "bounds":{
             "northeast":{
                "lat":55.0815,
                "lng":15.0418962
             },
             "southwest":{
                "lat":47.2701115,
                "lng":5.8663425
             }
          }
       },
       "currency_code":"EUR",
       "start_of_week":"monday"
    }

With one request, the API can infer that my Iocation is Germany, the currency, longitude and latitude and so much more.

通过一个请求,API可以推断出我的Iocation是德国,货币,经度和纬度等等。

结论 ( Conclusion )

If you find this project useful, be sure to give them a star on Github, make contributions and support the author however you can. Thanks!

如果您觉得这个项目有用,请确保在Github上给他们一个星,并尽力为作者提供支持。 谢谢!

翻译自: https://scotch.io/tutorials/open-source-ip-geo-location-api

开源api

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值