220v
젝무의 개발새발
220v
전체 방문자
오늘
어제
  • 분류 전체보기 (255)
    • AI (35)
      • ML, DL 학습 (30)
      • 논문 리뷰 (4)
      • 실습 및 프로젝트 (1)
    • Algorithm (145)
      • LeetCode (13)
      • 프로그래머스 (35)
      • 백준 (96)
      • 알고리즘, 문법 정리 (1)
    • Mobile, Application (17)
      • Flutter (10)
      • iOS, MacOS (7)
    • BackEnd (7)
      • Flask (1)
      • Node.js (5)
      • Spring, JSP..etc (1)
    • Web - FrontEnd (18)
      • JavaScript, JQuery, HTML, C.. (12)
      • React (6)
    • DataBase (1)
      • MySQL (1)
      • Firebase Firestore (0)
      • Supabase (0)
    • Git (1)
    • 기타 툴 및 오류 해결 (3)
    • 강의 (5)
      • Database (3)
      • 암호학 (2)
      • 알고리즘 (0)
    • 후기와 회고 (2)
    • 블로그 꾸미기 (1)
    • 일상과 이것저것 (20)
      • 맛집 (12)
      • 세상사는일 (4)
      • 도서리뷰 (1)
      • 이런저런 생각들 (잡글) (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • union-find
  • Prefix Sum
  • 프로그래머스
  • 백준
  • two pointer
  • 다익스트라
  • Dynamic Programming
  • IMPLEMENT
  • REACT
  • simulation
  • Backtracking
  • Mathematics
  • brute-Force
  • implementation
  • 구현
  • dfs
  • 티스토리챌린지
  • Priority Queue
  • dp
  • 위상 정렬
  • top-down
  • 오블완
  • binary search
  • BFS
  • Minimum Spanning Tree
  • Lis
  • topological sort
  • disjoint set
  • Greedy
  • bitmasking

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
220v

젝무의 개발새발

Mobile, Application/Flutter

[Google Maps API, Flutter] Google Maps(Places) API에서 response 언어 한국어로 설정하기

2022. 11. 16. 03:40
http (REST API) 관련이기 때문에 다른 프로젝트에서도 동일하게 적용 가능합니다.

Flutter 프로젝트를 진행하다, Google Places API를 이용해 텍스트로 장소를 검색하는 기능을 만드는데 response JSON에서 장소 이름이 영어로 나와서 화면에 띄워주기엔 좀 불편했다.

그래서 한국어로 response를 받을 수 있는 방법이 있는 지 찾아보았다.

 

우선, 기존에는 검색어 텍스트를 이용해 get요청으로 장소 정보를 받아오고 있었다.

String url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=";
String key = dotenv.env['GOOGLE_PLACES_API_2'] ?? "";

url += "$placeText_&key=$key";
var response = await http.get(Uri.parse(url));
var statusCode = response.statusCode;
var responseHeaders = response.headers;
var responseBody = response.body;

print("responseBody: $responseBody");
// 출력 결과
responseBody: {
  "results" : [
    "formatted_address" : "(영어 주소)"
    "geometry" : {
    	"location" : {
        "lat" : 37.560997,
        "lng" : 126.994728
      },
			...
    }
		"name" : "Hongje 3(sam)-dong"
		...
  ]
}

 

그러면, 출력 결과처럼 장소의 이름이 영어로 나오는 문제가 있었다. (물론 주소도..)

이걸 한국어로 바꾸기 위해선, get 요청 url에 language 옵션만 넣어 주면 되었다.

근데 영어로는 세세한 name이 나오지만, 한국어로는 같은 이름인 경우가 종종 있으니 주의.

예를 들면, "서울역"을 검색하면 서울역이라는 name이 4개나 있는 것을 볼 수 있다.

물론 주소는 서로 다 다름. ㅋㅋ.

String url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=";
String key = dotenv.env['GOOGLE_PLACES_API_2'] ?? "";

// language=ko 옵션을 추가했다.
url += "$placeText_&language=ko&key=$key";
var response = await http.get(Uri.parse(url));
var statusCode = response.statusCode;
var responseHeaders = response.headers;
var responseBody = response.body;

print("responseBody: $responseBody");
// 출력 결과
responseBody: {
  "results" : [
    "formatted_address" : "대한민국 서울특별시 서대문구 홍제3동"
    "geometry" : {
    	"location" : {
        "lat" : 37.560997,
        "lng" : 126.994728
      },
			...
    }
		"name" : "홍제3동"
		...
  ]
}

 

Reference

https://developers.google.com/maps/documentation/places/web-service/search-text

    'Mobile, Application/Flutter' 카테고리의 다른 글
    • [Flutter] BottomNavBar Icon에 알림 뱃지(Notification Badge) 달기
    • [Flutter] Warning: CocoaPods not installed. Skipping pod install. 오류
    • [Flutter] Container 안에서 이미지 사이즈 원하는대로 조정하기
    • [Flutter, Firebase] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly": 에러 (M1 Mac 환경)
    220v
    220v
    DGU CSE 20 / Apple Developer Academy @ POSTECH 2nd Jr.Learner.

    티스토리툴바