Class Geocoder
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
지오코더
주소와 지리적 좌표 간의 변환을 허용합니다.
아래 예에서는 이 클래스를 사용하여 콜로라도의 'Main St' 위치와 일치하는 상위 9개 항목을 찾아 지도에 추가한 후 새 Google 문서에 삽입하는 방법을 보여줍니다.
// Find the best matches for "Main St" in Colorado.
const response = Maps.newGeocoder()
// The latitudes and longitudes of southwest and northeast
// corners of Colorado, respectively.
.setBounds(36.998166, -109.045486, 41.001666, -102.052002)
.geocode('Main St');
// Create a Google Doc and map.
const doc = DocumentApp.create('My Map');
const map = Maps.newStaticMap();
// Add each result to the map and doc.
for (let i = 0; i < response.results.length && i < 9; i++) {
const result = response.results[i];
map.setMarkerStyle(null, null, i + 1);
map.addMarker(result.geometry.location.lat, result.geometry.location.lng);
doc.appendListItem(result.formatted_address);
}
// Add the finished map to the doc.
doc.appendImage(Utilities.newBlob(map.getMapImage(), 'image/png'));
참고 항목
자세한 문서
geocode(address)
지정된 주소의 대략적인 지리적 지점을 가져옵니다.
// Gets the geographic coordinates for Times Square.
const response = Maps.newGeocoder().geocode('Times Square, New York, NY');
for (let i = 0; i < response.results.length; i++) {
const result = response.results[i];
Logger.log(
'%s: %s, %s',
result.formatted_address,
result.geometry.location.lat,
result.geometry.location.lng,
);
}
매개변수
리턴
Object
: 여기에 설명된 대로 지오코딩 데이터가 포함된 JSON 객체입니다.
reverseGeocode(latitude, longitude)
지정된 지리적 지점의 대략적인 주소를 가져옵니다.
// Gets the address of a point in Times Square.
const response = Maps.newGeocoder().reverseGeocode(40.758577, -73.984464);
for (let i = 0; i < response.results.length; i++) {
const result = response.results[i];
Logger.log(
'%s: %s, %s',
result.formatted_address,
result.geometry.location.lat,
result.geometry.location.lng,
);
}
매개변수
이름 | 유형 | 설명 |
latitude | Number | 점의 위도 |
longitude | Number | 점의 경도 |
리턴
Object
: 여기에 설명된 대로 역지오코딩 데이터가 포함된 JSON 객체입니다.
참고 항목
setBounds(swLatitude, swLongitude, neLatitude, neLongitude)
결과에서 추가로 우선순위를 부여해야 하는 영역의 경계를 설정합니다.
// Creates a Geocoder that prefers points in the area of Manhattan.
const geocoder = Maps.newGeocoder().setBounds(
40.699642,
-74.021072,
40.877569,
-73.908548,
);
매개변수
이름 | 유형 | 설명 |
swLatitude | Number | 경계의 남서쪽 모서리의 위도 |
swLongitude | Number | 경계의 남서쪽 모서리의 경도 |
neLatitude | Number | 경계의 북동쪽 모서리의 위도 |
neLongitude | Number | 경계의 북동쪽 모서리의 경도 |
리턴
Geocoder
: 호출 체이닝을 용이하게 하는 Geocoder 객체
참고 항목
setLanguage(language)
결과에 사용할 언어를 설정합니다.
// Creates a Geocoder with the language set to French.
const geocoder = Maps.newGeocoder().setLanguage('fr');
매개변수
이름 | 유형 | 설명 |
language | String | BCP-47 언어 식별자 |
리턴
Geocoder
: 호출 체이닝을 용이하게 하는 Geocoder 객체입니다.
참고 항목
setRegion(region)
위치 이름을 해석할 때 사용할 지역을 설정합니다. 지원되는 지역 코드는 Google 지도에서 지원되는 ccTLD에 해당합니다. 예를 들어 지역 코드 'uk'는 'maps.google.co.uk'에 해당합니다.
// Creates a Geocoder with the region set to France.
const geocoder = Maps.newGeocoder().setRegion('fr');
매개변수
이름 | 유형 | 설명 |
region | String | 사용할 지역 코드 |
리턴
Geocoder
: 호출 체이닝을 용이하게 하는 Geocoder 객체
참고 항목
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eThe Geocoder class enables conversion between addresses and geographic coordinates (latitude and longitude).\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods for finding geographic points for an address (geocode) and vice-versa (reverseGeocode).\u003c/p\u003e\n"],["\u003cp\u003eYou can specify bounds for preferred results, language, and region for location interpretation.\u003c/p\u003e\n"],["\u003cp\u003eGeocoder uses a JSON object to represent the geocoding and reverse geocoding data.\u003c/p\u003e\n"],["\u003cp\u003eIt leverages the Google Geocoding API for its functionality and supports various region codes.\u003c/p\u003e\n"]]],[],null,["# Class Geocoder\n\nGeocoder\n\nAllows for the conversion between an address and geographical coordinates. \n\nThe example below shows how you can use this class find the top nine matches for the location\n\"Main St\" in Colorado, add them to a map, and then embed it in a new Google Doc.\n\n```javascript\n// Find the best matches for \"Main St\" in Colorado.\nconst response = Maps.newGeocoder()\n // The latitudes and longitudes of southwest and northeast\n // corners of Colorado, respectively.\n .setBounds(36.998166, -109.045486, 41.001666, -102.052002)\n .geocode('Main St');\n\n// Create a Google Doc and map.\nconst doc = DocumentApp.create('My Map');\nconst map = Maps.newStaticMap();\n\n// Add each result to the map and doc.\nfor (let i = 0; i \u003c response.results.length && i \u003c 9; i++) {\n const result = response.results[i];\n map.setMarkerStyle(null, null, i + 1);\n map.addMarker(result.geometry.location.lat, result.geometry.location.lng);\n doc.appendListItem(result.formatted_address);\n}\n\n// Add the finished map to the doc.\ndoc.appendImage(Utilities.newBlob(map.getMapImage(), 'image/png'));\n```\n\n#### See also\n\n- [Google Geocoding API](/maps/documentation/geocoding) \n\n### Methods\n\n| Method | Return type | Brief description |\n|--------------------------------------------------------------------------------------------------------|---------------|----------------------------------------------------------------------------------|\n| [geocode(address)](#geocode(String)) | `Object` | Gets the approximate geographic points for a given address. |\n| [reverseGeocode(latitude, longitude)](#reverseGeocode(Number,Number)) | `Object` | Gets the approximate addresses for a given geographic point. |\n| [setBounds(swLatitude, swLongitude, neLatitude, neLongitude)](#setBounds(Number,Number,Number,Number)) | [Geocoder](#) | Sets the bounds of an area that should be given extra preference in the results. |\n| [setLanguage(language)](#setLanguage(String)) | [Geocoder](#) | Sets the language to be used in the results. |\n| [setRegion(region)](#setRegion(String)) | [Geocoder](#) | Sets a region to use when interpreting location names. |\n\nDetailed documentation\n----------------------\n\n### `geocode(address)`\n\nGets the approximate geographic points for a given address.\n\n```javascript\n// Gets the geographic coordinates for Times Square.\nconst response = Maps.newGeocoder().geocode('Times Square, New York, NY');\nfor (let i = 0; i \u003c response.results.length; i++) {\n const result = response.results[i];\n Logger.log(\n '%s: %s, %s',\n result.formatted_address,\n result.geometry.location.lat,\n result.geometry.location.lng,\n );\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------|----------|-------------|\n| `address` | `String` | an address |\n\n#### Return\n\n\n`Object` --- a JSON Object containing the geocoding data, as described [here](/maps/documentation/geocoding#JSON)\n\n*** ** * ** ***\n\n### `reverse``Geocode(latitude, longitude)`\n\nGets the approximate addresses for a given geographic point.\n\n```javascript\n// Gets the address of a point in Times Square.\nconst response = Maps.newGeocoder().reverseGeocode(40.758577, -73.984464);\nfor (let i = 0; i \u003c response.results.length; i++) {\n const result = response.results[i];\n Logger.log(\n '%s: %s, %s',\n result.formatted_address,\n result.geometry.location.lat,\n result.geometry.location.lng,\n );\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------------|----------|----------------------------|\n| `latitude` | `Number` | the latitude of the point |\n| `longitude` | `Number` | the longitude of the point |\n\n#### Return\n\n\n`Object` --- a JSON Object containing the reverse geocoding data, as described [here](/maps/documentation/geocoding#ReverseGeocoding)\n\n#### See also\n\n- [Google Geocoding API](/maps/documentation/geocoding#JSON)\n\n*** ** * ** ***\n\n### `set``Bounds(swLatitude, swLongitude, neLatitude, neLongitude)`\n\nSets the bounds of an area that should be given extra preference in the results.\n\n```javascript\n// Creates a Geocoder that prefers points in the area of Manhattan.\nconst geocoder = Maps.newGeocoder().setBounds(\n 40.699642,\n -74.021072,\n 40.877569,\n -73.908548,\n);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------|----------|------------------------------------------------------|\n| `sw``Latitude` | `Number` | the latitude of the south west corner of the bounds |\n| `sw``Longitude` | `Number` | the longitude of the south west corner of the bounds |\n| `ne``Latitude` | `Number` | the latitude of the north east corner of the bounds |\n| `ne``Longitude` | `Number` | the longitude of the north east corner of the bounds |\n\n#### Return\n\n\n[Geocoder](#) --- the Geocoder object to facilitate chaining of calls\n\n#### See also\n\n- [Google Geocoding API](/maps/documentation/geocoding#Viewports)\n\n*** ** * ** ***\n\n### `set``Language(language)`\n\nSets the language to be used in the results.\n\n```javascript\n// Creates a Geocoder with the language set to French.\nconst geocoder = Maps.newGeocoder().setLanguage('fr');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|----------|------------------------------|\n| `language` | `String` | a BCP-47 language identifier |\n\n#### Return\n\n\n[Geocoder](#) --- the Geocoder object to facilitate chaining of calls.\n\n#### See also\n\n- [Encoded Polyline Format](/maps/documentation/utilities/polylinealgorithm)\n\n*** ** * ** ***\n\n### `set``Region(region)`\n\nSets a region to use when interpreting location names. The supported region codes correspond to\nthe ccTLDs supported by Google Maps. For example, the region code \"uk\" corresponds to\n\"maps.google.co.uk\".\n\n```javascript\n// Creates a Geocoder with the region set to France.\nconst geocoder = Maps.newGeocoder().setRegion('fr');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|----------|------------------------|\n| `region` | `String` | the region code to use |\n\n#### Return\n\n\n[Geocoder](#) --- the Geocoder object to facilitate chaining of calls\n\n#### See also\n\n- [Google Geocoding API](/maps/documentation/geocoding#RegionCodes)"]]