geoLocation

Prev Next

Classic/VPC 환경에서 이용 가능합니다.

IP 주소를 지정하여 지리적 위치 정보를 검색합니다.

요청

요청 형식을 설명합니다. 요청 형식은 다음과 같습니다.

메서드 URI
GET /geoLocation

요청 헤더

GeoLocation API에서 공통으로 사용하는 헤더에 대한 자세한 내용은 GeoLocation 요청 헤더를 참조해 주십시오.

요청 쿼리 파라미터

파라미터에 대한 설명은 다음과 같습니다.

필드 타입 필수 여부 설명
ip String Required 지역 정보를 알고자 하는 사용자 IP
ext String Optional 추가 정보 포함 여부
  • t | f (기본값)
    • t: 포함
    • f: 미포함
enc String Optional 응답 결과의 인코딩 방식
  • utf8 (기본값) | euckr
responseFormatType String Optional 응답 결과의 형식
  • xml (기본값) | json

요청 예시

요청 예시는 다음과 같습니다.

curl --location --request GET 'https://geolocation.apigw.ntruss.com/geolocation/v2/geoLocation
?ip=**.**.**.**
&ext=t
&enc=utf8
&responseFormatType=json'
--header 'x-ncp-apigw-timestamp: {Timestamp}'
--header 'x-ncp-iam-access-key: {Access Key}'
--header 'x-ncp-apigw-signature-v2: {API Gateway Signature}'

응답

응답 형식을 설명합니다.

응답 바디

응답 바디에 대한 설명은 다음과 같습니다.

필드 타입 필수 여부 설명
requestId String Required API 요청 ID
returnCode String Required 정상 코드는 0, 이외는 오류 코드
country String Required IP 주소에 해당하는 국가 코드
  • ISO 3166 표준 준수
  • EU (유럽), AP (아시아, 호주), A1 (Anonymous Proxy), A2 (Satellite Provider), O1 (Other Country) 포함
code String Required 대한민국 행정안전부에서 정의한 행정 구역 코드
r1 String Required 도, 광역시, 주
r2 String Required 시, 군, 구
r3 String Optional 동, 면, 읍
lat Number Optional 위도
long Number Optional 경도
net String Optional 통신사 이름

응답 상태 코드

응답 상태 코드에 대한 설명은 다음과 같습니다. 네이버 클라우드 플랫폼에서 공통으로 사용하는 응답 상태 코드에 대한 자세한 내용은 Ncloud API 응답 상태 코드를 참조해 주십시오.

HTTP 상태 코드 코드 메시지 설명
400 131000 No Entry 요청한 IP 주소에 대한 지역 정보를 찾을 수 없음
  • 해결 방법: 다른 IP를 이용하여 조회
400 131001 Invalid IP 공인 IP가 아니거나 IP 주소 형식이 잘못됨
400 131002 Internal Server Error GeoLocation 서버 오류
  • 해결 방법: 잠시 후 다시 시도하거나 문제가 지속될 경우에는 고객 지원으로 문의
400 131003 Quota Limit Reached 사용자가 설정한 API 호출 한도 초과
  • 해결 방법: 네이버 클라우드 플랫폼 콘솔의 Services > Application Services > GeoLocation > Quota Setting 메뉴에서 Quota를 늘려서 한도 변경
400 131004 Subscription Required GeoLocation 서비스 이용 신청 필요
  • 해결 방법: 네이버 클라우드 플랫폼 콘솔의 Services > Application Services > GeoLocation > Subscription 메뉴에서 이용 신청

응답 예시

응답 예시는 다음과 같습니다.

  • 국내, ext=f, responseFormatType=xml일 때
<?xml version="1.0" encoding="utf-8"?>
<getLocationResponse>
    <returnCode>0</returnCode>
    <requestId>c4e52003-****-****-****-66c93acfd0d2</requestId>
    <geoLocation>
        <country>KR</country>
        <code>41135*****</code>
        <r1>경기도</r1>
        <r2>성남시 분당구</r2>
    </geoLocation>
</getLocationResponse>
  • 국내, ext=f, responseFormatType=json일 때
{
    "returnCode": 0,
    "requestId": "c4e52003-****-****-****-66c93acfd0d2",
    "geoLocation": {
        "country": "KR",
        "code": "41135*****",
        "r1": "경기도",
        "r2": "성남시 분당구",
    }
}
  • 해외, ext=f, responseFormatType=xml일 때
<?xml version="1.0" encoding="utf-8"?>
<getLocationResponse>
    <returnCode>0</returnCode>
    <requestId>c4e52003-****-****-****-66c93acfd0d2</requestId>
    <geoLocation>
        <country>US</country>
        <code></code>
        <r1>California</r1>
        <r2>San Francisco</r2>
    </geoLocation>
</getLocationResponse>
  • 해외, ext=f, responseFormatType=json일 때
{
    "returnCode": 0,
    "requestId": "c4e52003-****-****-****-66c93acfd0d2",
    "geoLocation": {
        "country": "US",
        "code": "",
        "r1": "California",
        "r2": "San Francisco",
    }
}
  • 국내, ext=t, responseFormatType=xml일 때
<?xml version="1.0" encoding="utf-8"?>
<getLocationResponse>
    <returnCode>0</returnCode>
    <requestId>c4e52003-****-****-****-66c93acfd0d2</requestId>
    <geoLocation>
        <country>KR</country>
        <code>41135*****</code>
        <r1>경기도</r1>
        <r2>성남시 분당구</r2>
        <r3>정자동</r3>
        <lat>**.268***</lat>
        <long>**.030***</long>
        <net>Korea Telecom</net>
    </geoLocation>
</getLocationResponse>
  • 국내, ext=t, responseFormatType=json일 때
{
    "returnCode": 0,
    "requestId": "c4e52003-****-****-****-66c93acfd0d2",
    "geoLocation": {
        "country": "KR",
        "code": "41135*****",
        "r1": "경기도",
        "r2": "성남시 분당구",
        "r3": "정자동",
        "lat": **.268***,
        "long": **.030***,
        "net": "Korea Telecom"
    }
}
  • 해외, ext=t, responseFormatType=xml일 때
<?xml version="1.0" encoding="utf-8"?>
<getLocationResponse>
    <returnCode>0</returnCode>
    <requestId>c4e52003-****-****-****-66c93acfd0d2</requestId>    
    <geoLocation>
        <country>US</country>
        <code></code>
        <r1>California</r1>
        <r2>San Francisco</r2>
        <r3></r3>
        <lat>**.769***</lat>
        <long>-***.393***</long>
        <net>Fastly</net>
    </geoLocation>
</getLocationResponse>
  • 해외, ext=t, responseFormatType=xml일 때
{
    "returnCode": 0,
    "requestId": "c4e52003-****-****-****-66c93acfd0d2",
    "geoLocation": {
        "country": "US",
        "code": "",
        "r1": "California",
        "r2": "San Francisco",
        "r3": "",
        "lat": **.769***,
        "long": -***.393***,
        "net": "Fastly"
    }
}

예제

GeoLocation 예제 파일을 다운로드하여 GeoLocation API를 테스트하거나 예시로 활용할 수 있습니다.