Geolokasi dengan GeoIP2Link to this heading
The GeoIP2 object is a wrapper for the MaxMind geoip2 Python
library. [1]
In order to perform IP-based geolocation, the GeoIP2 object requires
the geoip2 Python package and the GeoIP Country and/or City
datasets in binary format (the CSV files will not work!), downloaded from e.g.
MaxMind or DB-IP websites. Grab the GeoLite2-Country.mmdb.gz and
GeoLite2-City.mmdb.gz files and unzip them in a directory corresponding to
the GEOIP_PATH setting.
Sebagai tambahan, sangat dianjurkan untuk memasang install libmaxminddb C library, sehingga geoip2 dapat mempengaruhi kecepatan tercepat pustaka C.
ContohLink to this heading
Here is an example of its usage:
>>> from django.contrib.gis.geoip2 import GeoIP2
>>> g = GeoIP2()
>>> g.country("google.com")
{'continent_code': 'NA',
'continent_name': 'North America',
'country_code': 'US',
'country_name': 'United States',
'is_in_european_union': False}
>>> g.city("72.14.207.99")
{'accuracy_radius': 1000,
'city': 'Mountain View',
'continent_code': 'NA',
'continent_name': 'North America',
'country_code': 'US',
'country_name': 'United States',
'is_in_european_union': False,
'latitude': 37.419200897216797,
'longitude': -122.05740356445312,
'metro_code': 807,
'postal_code': '94043',
'region_code': 'CA',
'region_name': 'California',
'time_zone': 'America/Los_Angeles',
'dma_code': 807,
'region': 'CA'}
>>> g.lat_lon("salon.com")
(39.0437, -77.4875)
>>> g.lon_lat("uh.edu")
(-95.4342, 29.834)
>>> g.geos("24.124.1.80").wkt
'POINT (-97 38)'
Acuan APILink to this heading
- class GeoIP2(path=None, cache=0, country=None, city=None)Link to this definition
Obyek GeoIP tidak membutuhkan parameter apapun untuk menggunakan pengaturan awalan. Bagaimanapun, pada pengaturan GEOIP_PATH sangat sedikit harus disetel dengan jalur dari tempat dari kumpulan data GeoIP anda. Kata kunci inisialisasi berikut mungkin digunakan untuk menyesuaikan apapun dari awalan.
Argumen Katakunci |
Deskripsi |
|---|---|
|
Direktori dasar dimana data GeoIP ditempatkan atau jalur penuh dimana berkas data kota atau negara ( |
|
Pengaturan cache ketika membuka dataset GeoIP. Mungkin berupa integer dalam (0, 1, 2, 4, 8) berhubungan ke pengaturan API C |
|
Nama dari berkas data negara GeoIP. Awalan pada |
|
Nama dari berkas data kota GeoIP. Awalan pada |
CaraLink to this heading
InstansiasiLink to this heading
- classmethod GeoIP2.open(path, cache)Link to this definition
Metode kelas ini memberi contoh obyek GeoIP dari jalur basisdata diberikan dan pengaturan cache diberikan.
MemintaLink to this heading
All the following querying routines may take an instance of
IPv4Address or IPv6Address, a string IP
address, or a fully qualified domain name (FQDN). For example,
IPv4Address("205.186.163.125"), "205.186.163.125", and
"djangoproject.com" would all be valid query parameters.
- GeoIP2.city(query)Link to this definition
Mengembalikan sebuah dictionary dari informasi kota untuk permintaan yang diberikan. Beberapa dari nilai dalam dictionary mungkin belum ditentukan (None).
- GeoIP2.country(query)Link to this definition
Mengembalikan sebuah dictionary dengan kode negara dan negara untuk permintaan yang diberikan.
- GeoIP2.country_code(query)Link to this definition
Mengembalikan kode negara terkait pada permintaan
- GeoIP2.country_name(query)Link to this definition
Mengembalikan nama negara terkait pada permintaan
Pengambilan KordinatLink to this heading
- GeoIP2.coords(query)Link to this definition
Mengembalikan sebuah tuple kordinat dari (longitude, latitude).
- GeoIP2.lon_lat(query)Link to this definition
Mengembalikan sebuah tuple kordinat dari (longitude, latitude).
- GeoIP2.lat_lon(query)Link to this definition
Mengembalikan sebuah tuple kordinat dari (latitude, longitude),
- GeoIP2.geos(query)Link to this definition
Mengembalikan obyek Point terkait pada permintaan
PengaturanLink to this heading
GEOIP_PATHLink to this heading
A string or pathlib.Path specifying the directory where the GeoIP data
files are located. This setting is required unless manually specified
with path keyword when initializing the GeoIP2 object.
GEOIP_COUNTRYLink to this heading
Namadasar untuk digunakan berkas data negara GeoIP. Nilai awal 'GeoLite2-Country.mmdb'.
GEOIP_CITYLink to this heading
Nama dasar digunakan untuk berkas data kota GeoIP. Awalan pada 'GeoLite2-City.mmdb'.
PengecualianLink to this heading
- exception GeoIP2ExceptionLink to this definition
The exception raised when an error occurs in the
GeoIP2wrapper. Exceptions from the underlyinggeoip2library are passed through unchanged.
Catatan kaki