위치 간 경로를 가져올 수 있습니다.
아래 예에서는 이 클래스를 사용하여 타임스 스퀘어에서 센트럴 파크까지의 길을 찾고, 먼저 링컨 센터에 들러 지도에 위치와 경로를 표시하고, 이메일로 지도를 전송하는 방법을 보여줍니다.
// Get the directions. const directions = Maps.newDirectionFinder() .setOrigin('Times Square, New York, NY') .addWaypoint('Lincoln Center, New York, NY') .setDestination('Central Park, New York, NY') .setMode(Maps.DirectionFinder.Mode.DRIVING) .getDirections(); const route = directions.routes[0]; // Set up marker styles. let markerLetterCode = 'A'.charCodeAt(); // Add markers to the map. const map = Maps.newStaticMap(); for (let i = 0; i < route.legs.length; i++) { const leg = route.legs[i]; if (i === 0) { // Add a marker for the start location of the first leg only. map.setMarkerStyle( Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.GREEN, String.fromCharCode(markerLetterCode), ); map.addMarker(leg.start_location.lat, leg.start_location.lng); markerLetterCode++; } map.setMarkerStyle( Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.GREEN, String.fromCharCode(markerLetterCode), ); map.addMarker(leg.end_location.lat, leg.end_location.lng); markerLetterCode++; } // Add a path for the entire route. map.addPath(route.overview_polyline.points); // Send the map in an email. const toAddress = Session.getActiveUser().getEmail(); MailApp.sendEmail( toAddress, 'Directions', `Please open: ${map.getMapUrl()}&key=YOUR_API_KEY`, { htmlBody: 'See below.<br/><img src="cid:mapImage">', inlineImages: { mapImage: Utilities.newBlob(map.getMapImage(), 'image/png'), }, }, );
참고 항목
메서드
자세한 문서
add Waypoint(latitude, longitude)
경로가 통과해야 하는 경유지를 점 (위도/경도)을 사용하여 추가합니다.
// Creates a DirectionFinder with a wapoint at Lincoln Center. const directionFinder = Maps.newDirectionFinder().addWaypoint( 40.772628, -73.984243, );
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
latitude | Number | 경유지의 위도입니다. |
longitude | Number | 경유지의 경도입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
add Waypoint(address)
주소를 사용하여 경로가 통과해야 하는 경유지를 추가합니다.
// Creates a DirectionFinder with a wapoint at Lincoln Center. const directionFinder = Maps.newDirectionFinder().addWaypoint( 'Lincoln Center, New York, NY', );
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
address | String | 주소입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
clear Waypoints()
현재 웨이포인트 세트를 지웁니다.
const directionFinder = Maps.newDirectionFinder(); // ... // Do something interesting here ... // ... // Remove all waypoints added with addWaypoint(). directionFinder.clearWaypoints();
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
get Directions()
설정된 출발지, 도착지, 기타 옵션을 사용하여 길찾기를 가져옵니다.
// Logs how long it takes to walk from Times Square to Central Park. const directions = Maps.newDirectionFinder() .setOrigin('Times Square, New York, NY') .setDestination('Central Park, New York, NY') .setMode(Maps.DirectionFinder.Mode.WALKING) .getDirections(); Logger.log(directions.routes[0].legs[0].duration.text);
리턴
Object - 여기에 설명된 대로 경로의 집합이 포함된 JSON 객체입니다.
참고 항목
set Alternatives(useAlternatives)
순위가 가장 높은 경로 대신 대체 경로를 반환할지 여부를 설정합니다 (기본값은 false). true인 경우 결과 객체의 routes 배열에 여러 항목이 포함될 수 있습니다.
// Creates a DirectionFinder with alternative routes enabled. const directionFinder = Maps.newDirectionFinder().setAlternatives(true);
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
use | Boolean | 대체 경로를 반환하려면 true, 그렇지 않으면 false |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
set Arrive(time)
도착 예정 시간을 설정합니다 (해당하는 경우).
// Creates a DirectionFinder with an arrival time of 2 hours from now. const now = new Date(); const arrive = new Date(now.getTime() + 2 * 60 * 60 * 1000); const directionFinder = Maps.newDirectionFinder().setArrive(arrive);
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
time | Date | 도착 시간입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
참고 항목
set Avoid(avoid)
특정 유형의 제한을 피할지 여부를 설정합니다.
// Creates a DirectionFinder that avoid highways. const directionFinder = Maps.newDirectionFinder().setAvoid( Maps.DirectionFinder.Avoid.HIGHWAYS, );
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
avoid | String | Avoid의 상수 값입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
참고 항목
set Depart(time)
원하는 출발 시간을 설정합니다 (해당하는 경우).
// Creates a DirectionFinder with a departure time of 1 hour from now. const now = new Date(); const depart = new Date(now.getTime() + 1 * 60 * 60 * 1000); const directionFinder = Maps.newDirectionFinder().setDepart(depart);
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
time | Date | 출발 시간입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
참고 항목
set Destination(latitude, longitude)
포인트 (위도/경도)를 사용하여 경로를 계산할 종료 위치를 설정합니다.
// Creates a DirectionFinder with the destination set to Central Park. const directionFinder = Maps.newDirectionFinder().setDestination( 40.777052, -73.975464, );
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
latitude | Number | 종료 위치의 위도입니다. |
longitude | Number | 종료 위치의 경도입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
set Destination(address)
주소를 사용하여 경로를 계산할 종료 위치를 설정합니다.
// Creates a DirectionFinder with the destination set to Central Park. const directionFinder = Maps.newDirectionFinder().setDestination( 'Central Park, New York, NY', );
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
address | String | 종료 주소입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
set Language(language)
안내에 사용할 언어를 설정합니다.
// Creates a DirectionFinder with the language set to French. const directionFinder = Maps.newDirectionFinder().setLanguage('fr');
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
language | String | BCP-47 언어 식별자입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
참고 항목
set Mode(mode)
이동 모드를 설정합니다 (기본값은 운전).
// Creates a DirectionFinder with the mode set to walking. const directionFinder = Maps.newDirectionFinder().setMode( Maps.DirectionFinder.Mode.WALKING, );
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
mode | String | Mode의 상수 값입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
참고 항목
set Optimize Waypoints(optimizeOrder)
더 효율적인 순서로 경유지를 재정렬하여 제공된 경로를 최적화할지 여부를 설정합니다 (기본값은 false).
// Creates a DirectionFinder with wapoint optimization enabled. const directionFinder = Maps.newDirectionFinder().setOptimizeWaypoints(true);
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
optimize | Boolean | true를 사용하여 주문을 최적화하고, 그렇지 않으면 false를 사용합니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
참고 항목
set Origin(latitude, longitude)
점을 사용하여 경로를 계산할 시작 위치를 설정합니다 (위도/경도).
// Creates a DirectionFinder with the origin set to Times Square. const directionFinder = Maps.newDirectionFinder().setOrigin( 40.759011, -73.984472, );
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
latitude | Number | 시작 위치의 위도입니다. |
longitude | Number | 시작 위치의 경도입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체
set Origin(address)
주소를 사용하여 경로를 계산할 시작 위치를 설정합니다.
// Creates a DirectionFinder with the origin set to Times Square. const directionFinder = Maps.newDirectionFinder().setOrigin( 'Times Square, New York, NY', );
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
address | String | 시작 주소입니다. |
리턴
Direction - 호출의 체이닝을 용이하게 하는 DirectionFinder 인스턴스입니다.
set Region(region)
위치 이름을 해석할 때 사용할 지역을 설정합니다. 지원되는 지역 코드는 Google 지도에서 지원하는 ccTLD에 해당합니다. 예를 들어 지역 코드 'uk'는 'maps.google.co.uk'에 해당합니다.
// Creates a DirectionFinder with the region set to France. const directionFinder = Maps.newDirectionFinder().setRegion('fr');
매개변수
| 이름 | 유형 | 설명 |
|---|---|---|
region | String | 사용할 지역 코드입니다. |
리턴
Direction - 호출 체이닝을 지원하는 DirectionFinder 객체