무료 javascript api를 제공해주고, 또 csv 나 binary 로 된 database 도 제공해준다!
좀더 강력한 기능이나, 꾸준한 업데이트를 받고 싶다면 구입해야 하지만...
이정도만 되도 충분히 사용할 거 같다. 좋네...
무료로 제공하는 메서드는 아래 표에서 위에 두개만 쓸수있다.
API
After the
geoip2.js
script is imported, you will have the geoip2
module in your namespace. This module provides four functions:Function | Description |
---|---|
geoip2.country(onSuccess, onError, options) | Calls the GeoIP2 Country endpoint using the routable IP address associated with the machine on which it is running. |
geoip2.city(onSuccess, onError, options) | Calls the GeoIP2 Precision City endpoint using the routable IP address associated with the machine on which it is running. |
geoip2.cityISPOrg(onSuccess, onError, options) | Calls the GeoIP2 Precision City/ISP/Org endpoint using the routable IP address associated with the machine on which it is running. Only available to paying customers. |
geoip2.omni(onSuccess, onError, options) | Calls the GeoIP2 Precision Omni endpoint using the routable IP address associated with the machine on which it is running. Only available to paying customers. |
Sample Code
<script type="text/javascript" src="//j.maxmind.com/js/geoip2.js"></script>
<script type="text/javascript">
var onSuccess = function(location){
alert(
"Lookup successful:\n\n"
+ JSON.stringify(location, undefined, 4)
);
};
var onError = function(error){
alert(
"Error:\n\n"
+ JSON.stringify(error, undefined, 4)
);
};
geoip2.city(onSuccess, onError);
</script>
Sample Object
The following is an example of a JavaScript object passed to the
successCallback
.{
"country": {
"iso_code": "KR",
"names": {
"zh-CN": "韩国",
"en": "South Korea",
"ja": "大韓民国",
"ru": "Южная Корея"
},
"geoname_id": 1835841
},
"city": {
"names": {
"en": "Seoul",
"ja": "ソウル特別市",
"ru": "Сеул"
},
"geoname_id": 1835848
},
"subdivisions": [
{
"iso_code": "11",
"names": {
"en": "Seoul"
},
"geoname_id": 1835847
},
{
"iso_code": "11",
"names": {
"en": "Seoul"
},
"geoname_id": 1835847
}
],
"location": {
"longitude": "126.977969",
"latitude": "37.566535",
"time_zone": "Asia/Seoul"
},
"continent": {
"names": {
"zh-CN": "亚洲",
"en": "Asia",
"ja": "アジア",
"ru": "Азия"
},
"continent_code": "AS",
"geoname_id": 6255147
},
"traits": {
"ip_address": "152.99.241.12"
},
"registered_country": {
"iso_code": "KR",
"names": {
"en": "South Korea",
"zh-CN": "韩国",
"ja": "大韓民国",
"ru": "Южная Корея"
},
"geoname_id": 1835841
},
"postal": {},
"represented_country": {
"names": {}
}
}
Maxmind 를 무료로 쓰기위해서는 도메인 등록만하면 된다.
자 이제 ㄱㄱ
댓글 없음:
댓글 쓰기