Class Geocoder

지오코더

주소와 지리적 좌표 간의 변환을 허용합니다.
아래 예는 이 클래스를 사용하여 콜로라도의 'Main St' 위치와 일치하는 상위 9개 항목을 찾아 지도에 추가한 다음 새 Google 문서에 삽입하는 방법을 보여줍니다.

// Find the best matches for "Main St" in Colorado.
var 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.
var doc = DocumentApp.create('My Map');
var map = Maps.newStaticMap();

// Add each result to the map and doc.
for (var i = 0; i < response.results.length && i < 9; i++) {
  var 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)Object지정된 주소의 대략적인 지리적 지점을 가져옵니다.
reverseGeocode(latitude, longitude)Object지정된 지리적 지점의 대략적인 주소를 가져옵니다.
setBounds(swLatitude, swLongitude, neLatitude, neLongitude)Geocoder결과에 추가 환경설정을 지정해야 하는 영역의 경계를 설정합니다.
setLanguage(language)Geocoder결과에 사용할 언어를 설정합니다.
setRegion(region)Geocoder위치 이름을 해석할 때 사용할 지역을 설정합니다.

자세한 문서

geocode(address)

지정된 주소의 대략적인 지리적 지점을 가져옵니다.

// Gets the geographic coordinates for Times Square.
var response = Maps.newGeocoder().geocode('Times Square, New York, NY');
for (var i = 0; i < response.results.length; i++) {
  var result = response.results[i];
  Logger.log('%s: %s, %s', result.formatted_address, result.geometry.location.lat,
      result.geometry.location.lng);
}

매개변수

이름유형설명
addressString주소

리턴

Object - 여기에 설명된 대로 지오코딩 데이터가 포함된 JSON 객체


reverseGeocode(latitude, longitude)

지정된 지리적 지점의 대략적인 주소를 가져옵니다.

// Gets the address of a point in Times Square.
var response = Maps.newGeocoder().reverseGeocode(40.758577, -73.984464);
for (var i = 0; i < response.results.length; i++) {
  var result = response.results[i];
  Logger.log('%s: %s, %s', result.formatted_address, result.geometry.location.lat,
      result.geometry.location.lng);
}

매개변수

이름유형설명
latitudeNumber지점의 위도
longitudeNumber점의 경도

리턴

Object - 여기에 설명된 대로 역 지오코딩 데이터가 포함된 JSON 객체

참고 항목


setBounds(swLatitude, swLongitude, neLatitude, neLongitude)

결과에 추가 환경설정을 지정해야 하는 영역의 경계를 설정합니다.

// Creates a Geocoder that prefers points in the area of Manhattan.
var geocoder = Maps.newGeocoder()
    .setBounds(40.699642, -74.021072, 40.877569, -73.908548);

매개변수

이름유형설명
swLatitudeNumber경계 남서쪽 모서리의 위도
swLongitudeNumber경계 남서쪽 모서리의 경도
neLatitudeNumber경계 북동쪽 모서리의 위도
neLongitudeNumber경계 북동쪽 모서리의 경도

리턴

Geocoder - 호출 체인을 용이하게 하는 지오코더 객체

참고 항목


setLanguage(language)

결과에 사용할 언어를 설정합니다.

// Creates a Geocoder with the language set to French.
var geocoder = Maps.newGeocoder().setLanguage('fr');

매개변수

이름유형설명
languageStringBCP-47 언어 식별자

리턴

Geocoder: 호출 체인을 용이하게 하는 지오코더 객체입니다.

참고 항목


setRegion(region)

위치 이름을 해석할 때 사용할 지역을 설정합니다. 지원되는 지역 코드는 Google 지도에서 지원하는 ccTLD에 해당합니다. 예를 들어 지역 코드 'uk'는 'maps.google.co.uk'에 해당합니다.

// Creates a Geocoder with the region set to France.
var geocoder = Maps.newGeocoder().setRegion('fr');

매개변수

이름유형설명
regionString사용할 지역 코드

리턴

Geocoder - 호출 체인을 용이하게 하는 지오코더 객체

참고 항목