{"id":3634,"date":"2021-10-16T16:50:42","date_gmt":"2021-10-16T07:50:42","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=3634"},"modified":"2021-10-18T18:06:05","modified_gmt":"2021-10-18T09:06:05","slug":"kakao-map-rest-api-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=3634","title":{"rendered":"Kakao Map REST API \uc0ac\uc6a9\ud558\uae30"},"content":{"rendered":"<h1>Kakao Map REST API \uc0ac\uc6a9\ud558\uae30<\/h1>\n<p><a href=\"https:\/\/youngest-programming.tistory.com\/163\">\ucc38\uc870<\/a><\/p>\n<p><a href=\"https:\/\/developers.kakao.com\/docs\/latest\/ko\/local\/dev-guide#search-by-keyword\">\ucc38\uc870<\/a><\/p>\n<p><code>Kakao Map REST API<\/code> \ub97c \uc774\uc6a9\ud558\uc5ec \uc74c\uc2dd\uc810 \uac80\uc0c9\uc744 \uad6c\ud604\ud574 \ubd05\ub2c8\ub2e4.<\/p>\n<p>\ucc38\uace0\ub85c, REST API \ub294 \uc544\uc774\ud53c \uc81c\ud55c\uc774 \uc5c6\uc2b5\ub2c8\ub2e4.<\/p>\n<h2>\uac10\uc0ac\uc778\uc0ac<\/h2>\n<p><a href=\"https:\/\/youngest-programming.tistory.com\/163\">https:\/\/youngest-programming.tistory.com\/163<\/a> \uc5d0 \uac10\uc0ac\ud569\ub2c8\ub2e4.<\/p>\n<p>1-2 \uc8fc\uc758 \ub178\uac00\ub2e4 \ub610\ub294 \uc0bd\uc9c8\uc744 \uc904\uc5ec\uc8fc\uc168\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uadf8\ub0e5 \uc18c\uc2a4 \uc0ac\uc774\ud2b8 \uc18c\uac1c\ud558\uace0 \ub05d\ub0bc\uae4c \ud558\ub2e4\uac00 \uac11\uc790\uae30 \ube14\ub85c\uadf8 \ud3ed\ud30c\ub418\ub294\uac83 \uc544\ub2d0\uae4c \ud574\uc11c \uacf5\uac1c\ud558\uc2e0 \uc18c\uc2a4\ucf54\ub4dc \ubcf5\uc0ac\ud574 \ub193\uc2b5\ub2c8\ub2e4.<\/p>\n<h2>\uc758\uc874\uc131 \ucd94\uac00<\/h2>\n<pre><code class=\"language-gradle\">dependencies {\n    implementation &#039;com.squareup.retrofit2:retrofit:2.6.4&#039;\n    implementation &#039;com.squareup.retrofit2:converter-gson:2.6.4&#039;\n    implementation &#039;com.squareup.retrofit2:converter-scalars:2.6.4&#039;\n    implementation &#039;org.jetbrains:annotations:15.0&#039;\n}<\/code><\/pre>\n<h2>6 \uac1c\uc758 \ud074\ub798\uc2a4 \uc0dd\uc131<\/h2>\n<pre><code class=\"language-java\">public class ApiClient {\n\n    private static final String BASE_URL = &quot;https:\/\/dapi.kakao.com\/&quot;;\n    private static Retrofit retrofit;\n\n    public static Retrofit getApiClient(){\n        if(retrofit == null){\n            retrofit = new Retrofit.Builder()\n                    .baseUrl(BASE_URL)\n                    .addConverterFactory(GsonConverterFactory.create())\n                    .build();\n        }\n        return  retrofit;\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-java\">public interface ApiInterface {\n\n    \/\/ \uc7a5\uc18c\uc774\ub984\uc73c\ub85c \uac80\uc0c9\n    @GET(&quot;v2\/local\/search\/keyword.json&quot;)\n    Call&lt;CategoryResult&gt; getSearchLocation(\n            @Header(&quot;Authorization&quot;) String token,\n            @Query(&quot;query&quot;) String query,\n            @Query(&quot;category_group_code&quot;) String categoryGroupCode,\n            @Query(&quot;size&quot;) int size,            \/\/ 1 ~ 15\n            @Query(&quot;page&quot;) int page,            \/\/ 1 ~ 45\n            @Query(&quot;sort&quot;) String sort,         \/\/ distance \ub610\ub294 accuracy (\uae30\ubcf8\uac12: accuracy)\n            @Query(&quot;x&quot;) String x,\n            @Query(&quot;y&quot;) String y\n    );\n\n    \/\/ \uce74\ud14c\uace0\ub9ac\ub85c \uac80\uc0c9\n    @GET(&quot;v2\/local\/search\/category.json&quot;)\n    Call&lt;CategoryResult&gt; getSearchCategory(\n            @Header(&quot;Authorization&quot;) String token,\n            @Query(&quot;category_group_code&quot;) String category_group_code,\n            @Query(&quot;x&quot;) String x,\n            @Query(&quot;y&quot;) String y,\n            @Query(&quot;radius&quot;) int radius\n    );\n\n    \/\/ \uc7a5\uc18c\uc774\ub984\uc73c\ub85c \ud2b9\uc815\uc704\uce58\uae30\uc900\uc73c\ub85c \uac80\uc0c9\n    @GET(&quot;v2\/local\/search\/keyword.json&quot;)\n    Call&lt;CategoryResult&gt; getSearchLocationDetail(\n            @Header(&quot;Authorization&quot;) String token,\n            @Query(&quot;query&quot;) String query,\n            @Query(&quot;x&quot;) String x,\n            @Query(&quot;y&quot;) String y,\n            @Query(&quot;size&quot;) int size\n    );\n\n    \/\/\uc8fc\uc18c\ub85c \uac80\uc0c9 (\uc544\uc9c1\uc548\uc4f0\ub294\uc911)\n    @GET(&quot;v2\/local\/search\/address.json&quot;)\n    Call&lt;CategoryResult&gt; getSearchAddress(\n            @Header(&quot;Authorization&quot;) String token,\n            @Query(&quot;query&quot;) String query,\n            @Query(&quot;size&quot;) int size\n    );\n}<\/code><\/pre>\n<pre><code class=\"language-java\">public class CategoryResult implements Parcelable {\n\n    @SerializedName(&quot;meta&quot;)\n    @Expose\n    private Meta meta;\n    @SerializedName(&quot;documents&quot;)\n    @Expose\n    private List&lt;Document&gt; documents = null;\n\n    public Meta getMeta() {\n        return meta;\n    }\n\n    public void setMeta(Meta meta) {\n        this.meta = meta;\n    }\n\n    public List&lt;Document&gt; getDocuments() {\n        return documents;\n    }\n\n    public void setDocuments(List&lt;Document&gt; documents) {\n        this.documents = documents;\n    }\n\n    @Override\n    public int describeContents() {\n        return 0;\n    }\n\n    @Override\n    public void writeToParcel(Parcel dest, int flags) {\n        dest.writeParcelable(this.meta, flags);\n        dest.writeList(this.documents);\n    }\n\n    public CategoryResult() {\n    }\n\n    protected CategoryResult(Parcel in) {\n        this.meta = in.readParcelable(Meta.class.getClassLoader());\n        this.documents = new ArrayList&lt;Document&gt;();\n        in.readList(this.documents, Document.class.getClassLoader());\n    }\n\n    public static final Parcelable.Creator&lt;CategoryResult&gt; CREATOR = new Parcelable.Creator&lt;CategoryResult&gt;() {\n        @Override\n        public CategoryResult createFromParcel(Parcel source) {\n            return new CategoryResult(source);\n        }\n\n        @Override\n        public CategoryResult[] newArray(int size) {\n            return new CategoryResult[size];\n        }\n    };\n}<\/code><\/pre>\n<pre><code class=\"language-java\">public class Document implements Parcelable {\n\n    @SerializedName(&quot;place_name&quot;)\n    @Expose\n    private String placeName;\n    @SerializedName(&quot;distance&quot;)\n    @Expose\n    private String distance;\n    @SerializedName(&quot;place_url&quot;)\n    @Expose\n    private String placeUrl;\n    @SerializedName(&quot;category_name&quot;)\n    @Expose\n    private String categoryName;\n    @SerializedName(&quot;address_name&quot;)\n    @Expose\n    private String addressName;\n    @SerializedName(&quot;road_address_name&quot;)\n    @Expose\n    private String roadAddressName;\n    @SerializedName(&quot;id&quot;)\n    @Expose\n    private String id;\n    @SerializedName(&quot;phone&quot;)\n    @Expose\n    private String phone;\n    @SerializedName(&quot;category_group_code&quot;)\n    @Expose\n    private String categoryGroupCode;\n    @SerializedName(&quot;category_group_name&quot;)\n    @Expose\n    private String categoryGroupName;\n    @SerializedName(&quot;x&quot;)\n    @Expose\n    private String x;\n    @SerializedName(&quot;y&quot;)\n    @Expose\n    private String y;\n\n    public String getPlaceName() {\n        return placeName;\n    }\n\n    public void setPlaceName(String placeName) {\n        this.placeName = placeName;\n    }\n\n    public String getDistance() {\n        return distance;\n    }\n\n    public void setDistance(String distance) {\n        this.distance = distance;\n    }\n\n    public String getPlaceUrl() {\n        return placeUrl;\n    }\n\n    public void setPlaceUrl(String placeUrl) {\n        this.placeUrl = placeUrl;\n    }\n\n    public String getCategoryName() {\n        return categoryName;\n    }\n\n    public void setCategoryName(String categoryName) {\n        this.categoryName = categoryName;\n    }\n\n    public String getAddressName() {\n        return addressName;\n    }\n\n    public void setAddressName(String addressName) {\n        this.addressName = addressName;\n    }\n\n    public String getRoadAddressName() {\n        return roadAddressName;\n    }\n\n    public void setRoadAddressName(String roadAddressName) {\n        this.roadAddressName = roadAddressName;\n    }\n\n    public String getId() {\n        return id;\n    }\n\n    public void setId(String id) {\n        this.id = id;\n    }\n\n    public String getPhone() {\n        return phone;\n    }\n\n    public void setPhone(String phone) {\n        this.phone = phone;\n    }\n\n    public String getCategoryGroupCode() {\n        return categoryGroupCode;\n    }\n\n    public void setCategoryGroupCode(String categoryGroupCode) {\n        this.categoryGroupCode = categoryGroupCode;\n    }\n\n    public String getCategoryGroupName() {\n        return categoryGroupName;\n    }\n\n    public void setCategoryGroupName(String categoryGroupName) {\n        this.categoryGroupName = categoryGroupName;\n    }\n\n    public String getX() {\n        return x;\n    }\n\n    public void setX(String x) {\n        this.x = x;\n    }\n\n    public String getY() {\n        return y;\n    }\n\n    public void setY(String y) {\n        this.y = y;\n    }\n\n    @Override\n    public int describeContents() {\n        return 0;\n    }\n\n    @Override\n    public void writeToParcel(Parcel dest, int flags) {\n        dest.writeString(this.placeName);\n        dest.writeString(this.distance);\n        dest.writeString(this.placeUrl);\n        dest.writeString(this.categoryName);\n        dest.writeString(this.addressName);\n        dest.writeString(this.roadAddressName);\n        dest.writeString(this.id);\n        dest.writeString(this.phone);\n        dest.writeString(this.categoryGroupCode);\n        dest.writeString(this.categoryGroupName);\n        dest.writeString(this.x);\n        dest.writeString(this.y);\n    }\n\n    public Document() {\n    }\n\n    protected Document(Parcel in) {\n        this.placeName = in.readString();\n        this.distance = in.readString();\n        this.placeUrl = in.readString();\n        this.categoryName = in.readString();\n        this.addressName = in.readString();\n        this.roadAddressName = in.readString();\n        this.id = in.readString();\n        this.phone = in.readString();\n        this.categoryGroupCode = in.readString();\n        this.categoryGroupName = in.readString();\n        this.x = in.readString();\n        this.y = in.readString();\n    }\n\n    public static final Parcelable.Creator&lt;Document&gt; CREATOR = new Parcelable.Creator&lt;Document&gt;() {\n        @Override\n        public Document createFromParcel(Parcel source) {\n            return new Document(source);\n        }\n\n        @Override\n        public Document[] newArray(int size) {\n            return new Document[size];\n        }\n    };\n}<\/code><\/pre>\n<pre><code class=\"language-java\">public class Meta implements Parcelable {\n\n    @SerializedName(&quot;same_name&quot;)\n    @Expose\n    private SameName sameName;\n    @SerializedName(&quot;pageable_count&quot;)\n    @Expose\n    private Integer pageableCount;\n    @SerializedName(&quot;total_count&quot;)\n    @Expose\n    private Integer totalCount;\n    @SerializedName(&quot;is_end&quot;)\n    @Expose\n    private Boolean isEnd;\n\n    public SameName getSameName() {\n        return sameName;\n    }\n\n    public void setSameName(SameName sameName) {\n        this.sameName = sameName;\n    }\n\n    public Integer getPageableCount() {\n        return pageableCount;\n    }\n\n    public void setPageableCount(Integer pageableCount) {\n        this.pageableCount = pageableCount;\n    }\n\n    public Integer getTotalCount() {\n        return totalCount;\n    }\n\n    public void setTotalCount(Integer totalCount) {\n        this.totalCount = totalCount;\n    }\n\n    public Boolean getIsEnd() {\n        return isEnd;\n    }\n\n    public void setIsEnd(Boolean isEnd) {\n        this.isEnd = isEnd;\n    }\n\n    @Override\n    public int describeContents() {\n        return 0;\n    }\n\n    @Override\n    public void writeToParcel(Parcel dest, int flags) {\n        dest.writeParcelable(this.sameName, flags);\n        dest.writeValue(this.pageableCount);\n        dest.writeValue(this.totalCount);\n        dest.writeValue(this.isEnd);\n    }\n\n    public Meta() {\n    }\n\n    protected Meta(Parcel in) {\n        this.sameName = in.readParcelable(SameName.class.getClassLoader());\n        this.pageableCount = (Integer) in.readValue(Integer.class.getClassLoader());\n        this.totalCount = (Integer) in.readValue(Integer.class.getClassLoader());\n        this.isEnd = (Boolean) in.readValue(Boolean.class.getClassLoader());\n    }\n\n    public static final Creator&lt;Meta&gt; CREATOR = new Creator&lt;Meta&gt;() {\n        @Override\n        public Meta createFromParcel(Parcel source) {\n            return new Meta(source);\n        }\n\n        @Override\n        public Meta[] newArray(int size) {\n            return new Meta[size];\n        }\n    };\n}<\/code><\/pre>\n<pre><code class=\"language-java\">public class SameName implements Parcelable {\n\n    @SerializedName(&quot;region&quot;)\n    @Expose\n    private List&lt;Object&gt; region = null;\n    @SerializedName(&quot;keyword&quot;)\n    @Expose\n    private String keyword;\n    @SerializedName(&quot;selected_region&quot;)\n    @Expose\n    private String selectedRegion;\n\n    public List&lt;Object&gt; getRegion() {\n        return region;\n    }\n\n    public void setRegion(List&lt;Object&gt; region) {\n        this.region = region;\n    }\n\n    public String getKeyword() {\n        return keyword;\n    }\n\n    public void setKeyword(String keyword) {\n        this.keyword = keyword;\n    }\n\n    public String getSelectedRegion() {\n        return selectedRegion;\n    }\n\n    public void setSelectedRegion(String selectedRegion) {\n        this.selectedRegion = selectedRegion;\n    }\n\n    @Override\n    public int describeContents() {\n        return 0;\n    }\n\n    @Override\n    public void writeToParcel(Parcel dest, int flags) {\n        dest.writeList(this.region);\n        dest.writeString(this.keyword);\n        dest.writeString(this.selectedRegion);\n    }\n\n    public SameName() {\n    }\n\n    protected SameName(Parcel in) {\n        this.region = new ArrayList&lt;Object&gt;();\n        in.readList(this.region, Object.class.getClassLoader());\n        this.keyword = in.readString();\n        this.selectedRegion = in.readString();\n    }\n\n    public static final Creator&lt;SameName&gt; CREATOR = new Creator&lt;SameName&gt;() {\n        @Override\n        public SameName createFromParcel(Parcel source) {\n            return new SameName(source);\n        }\n\n        @Override\n        public SameName[] newArray(int size) {\n            return new SameName[size];\n        }\n    };\n}<\/code><\/pre>\n<h2>API \ud638\ucd9c<\/h2>\n<pre><code class=\"language-java\">ApiInterface apiInterface = ApiClient.getApiClient().create(ApiInterface.class);\nCall&lt;CategoryResult&gt; call = apiInterface.getSearchLocation(\n        getString(R.string.restapi_key),\n        searchText,\n        &quot;FD6&quot;,      \/\/ \uc74c\uc2dd\uc810\n        15,\n        1,\n        &quot;&quot;,\n        &quot;&quot;,\n        &quot;&quot;);\ncall.enqueue(new Callback&lt;CategoryResult&gt;() {\n    @SuppressLint(&quot;NotifyDataSetChanged&quot;)\n    @Override\n    public void onResponse(@NotNull Call&lt;CategoryResult&gt; call, @NotNull Response&lt;CategoryResult&gt; response) {\n        if (response.isSuccessful()) {\n            assert response.body() != null;\n            adapter.clear();\n            for (Document document : response.body().getDocuments()) {\n                \/\/ Log.e(&quot;getKeyHash&quot;, document.getPlaceName());\n                adapter.add(document);\n            }\n            adapter.notifyDataSetChanged();\n        } else {\n            Log.e(&quot;getKeyHash 111&quot;, response.message());\n        }\n    }\n\n    @Override\n    public void onFailure(@NotNull Call&lt;CategoryResult&gt; call, @NotNull Throwable t) {\n\n    }\n});<\/code><\/pre>\n<h2>\uc8fc\uc758\uc0ac\ud56d<\/h2>\n<p>REST API \ud0a4\ub294 <code>KakaoAK ebf5cef251XXXXXXXXXXXXXX<\/code> \uc640 \uac19\uc774 <code>KakaoAK <\/code> \ub97c \uac19\uc774 \ubd99\uc5ec\uc8fc\uc5b4\uc57c \ud569\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kakao Map REST API \uc0ac\uc6a9\ud558\uae30 \ucc38\uc870 \ucc38\uc870 Kakao Map REST API \ub97c \uc774\uc6a9\ud558\uc5ec \uc74c\uc2dd\uc810 \uac80\uc0c9\uc744 \uad6c\ud604\ud574 \ubd05\ub2c8\ub2e4. \ucc38\uace0\ub85c, REST API \ub294 \uc544\uc774\ud53c \uc81c\ud55c\uc774 \uc5c6\uc2b5\ub2c8\ub2e4. \uac10\uc0ac\uc778\uc0ac https:\/\/youngest-programming.tistory.com\/163 \uc5d0 \uac10\uc0ac\ud569\ub2c8\ub2e4. 1-2 \uc8fc\uc758 \ub178\uac00\ub2e4 \ub610\ub294 \uc0bd\uc9c8\uc744 \uc904\uc5ec\uc8fc\uc168\uc2b5\ub2c8\ub2e4. \uadf8\ub0e5 \uc18c\uc2a4 \uc0ac\uc774\ud2b8 \uc18c\uac1c\ud558\uace0 \ub05d\ub0bc\uae4c \ud558\ub2e4\uac00 \uac11\uc790\uae30 \ube14\ub85c\uadf8 \ud3ed\ud30c\ub418\ub294\uac83 \uc544\ub2d0\uae4c \ud574\uc11c \uacf5\uac1c\ud558\uc2e0 \uc18c\uc2a4\ucf54\ub4dc \ubcf5\uc0ac\ud574 \ub193\uc2b5\ub2c8\ub2e4. \uc758\uc874\uc131 \ucd94\uac00 dependencies { implementation &#039;com.squareup.retrofit2:retrofit:2.6.4&#039;\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=3634\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-3634","post","type-post","status-publish","format-standard","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3634","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3634"}],"version-history":[{"count":8,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3634\/revisions"}],"predecessor-version":[{"id":3652,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3634\/revisions\/3652"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3634"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}