1 | declare namespace google.maps {
|
2 | class DirectionsService {
|
3 | route(request: DirectionsRequest, callback: (result: DirectionsResult, status: DirectionsStatus) => void): void;
|
4 | }
|
5 |
|
6 | /** A directions query to be sent to the DirectionsService. */
|
7 | interface DirectionsRequest {
|
8 | /**
|
9 | * If true, instructs the Directions service to avoid ferries where
|
10 | * possible. Optional.
|
11 | */
|
12 | avoidFerries?: boolean;
|
13 | /**
|
14 | * If true, instructs the Directions service to avoid highways where
|
15 | * possible. Optional.
|
16 | */
|
17 | avoidHighways?: boolean;
|
18 | /**
|
19 | * If true, instructs the Directions service to avoid toll roads where
|
20 | * possible. Optional.
|
21 | */
|
22 | avoidTolls?: boolean;
|
23 | /**
|
24 | * Location of destination. This can be specified as either a string to be
|
25 | * geocoded, or a LatLng, or a Place. Required.
|
26 | */
|
27 | destination?: string | LatLng | LatLngLiteral | Place;
|
28 | /** Deprecated. Use drivingOptions field instead */
|
29 | durationInTraffic?: boolean;
|
30 | /**
|
31 | * Settings that apply only to requests where travelMode is DRIVING. This
|
32 | * object will have no effect for other travel modes.
|
33 | */
|
34 | drivingOptions?: DrivingOptions;
|
35 | /**
|
36 | * If set to true, the DirectionService will attempt to re-order the
|
37 | * supplied intermediate waypoints to minimize overall cost of the route. If
|
38 | * waypoints are optimized, inspect DirectionsRoute.waypoint_order in the
|
39 | * response to determine the new ordering.
|
40 | */
|
41 | optimizeWaypoints?: boolean;
|
42 | /**
|
43 | * Location of origin. This can be specified as either a string to be
|
44 | * geocoded, or a LatLng, or a Place. Required.
|
45 | */
|
46 | origin?: string | LatLng | LatLngLiteral | Place;
|
47 | /** Whether or not route alternatives should be provided. Optional. */
|
48 | provideRouteAlternatives?: boolean;
|
49 | /** Region code used as a bias for geocoding requests. Optional. */
|
50 | region?: string;
|
51 | /**
|
52 | * Settings that apply only to requests where travelMode is TRANSIT. This
|
53 | * object will have no effect for other travel modes.
|
54 | */
|
55 | transitOptions?: TransitOptions;
|
56 | /** Type of routing requested. Required. */
|
57 | travelMode?: TravelMode;
|
58 | /**
|
59 | * Preferred unit system to use when displaying distance. Defaults to the
|
60 | * unit system used in the country of origin.
|
61 | */
|
62 | unitSystem?: UnitSystem;
|
63 | /**
|
64 | * Array of intermediate waypoints. Directions will be calculated from the
|
65 | * origin to the destination by way of each waypoint in this array. The
|
66 | * maximum allowed waypoints is 8, plus the origin, and destination. Premium
|
67 | * Plan customers are allowed 23 waypoints, plus the origin, and
|
68 | * destination. Waypoints are not supported for transit directions.
|
69 | * Optional.
|
70 | */
|
71 | waypoints?: DirectionsWaypoint[];
|
72 | }
|
73 |
|
74 | enum DirectionsStatus {
|
75 | INVALID_REQUEST = 'INVALID_REQUEST',
|
76 | MAX_WAYPOINTS_EXCEEDED = 'MAX_WAYPOINTS_EXCEEDED',
|
77 | NOT_FOUND = 'NOT_FOUND',
|
78 | OK = 'OK',
|
79 | OVER_QUERY_LIMIT = 'OVER_QUERY_LIMIT',
|
80 | REQUEST_DENIED = 'REQUEST_DENIED',
|
81 | UNKNOWN_ERROR = 'UNKNOWN_ERROR',
|
82 | ZERO_RESULTS = 'ZERO_RESULTS',
|
83 | }
|
84 |
|
85 | interface DirectionsResult {
|
86 | geocoded_waypoints: DirectionsGeocodedWaypoint[];
|
87 | routes: DirectionsRoute[];
|
88 | }
|
89 |
|
90 | class DirectionsRenderer extends MVCObject {
|
91 | constructor(opts?: DirectionsRendererOptions);
|
92 | getDirections(): DirectionsResult;
|
93 | getMap(): Map;
|
94 | getPanel(): Element;
|
95 | getRouteIndex(): number;
|
96 | setDirections(directions: DirectionsResult): void;
|
97 | setMap(map: Map | null): void;
|
98 | setOptions(options: DirectionsRendererOptions): void;
|
99 | setPanel(panel: Element): void;
|
100 | setRouteIndex(routeIndex: number): void;
|
101 | }
|
102 |
|
103 | interface DirectionsRendererOptions {
|
104 | directions?: DirectionsResult;
|
105 | draggable?: boolean;
|
106 | hideRouteList?: boolean;
|
107 | infoWindow?: InfoWindow;
|
108 | map?: Map;
|
109 | markerOptions?: MarkerOptions;
|
110 | panel?: Element;
|
111 | polylineOptions?: PolylineOptions;
|
112 | preserveViewport?: boolean;
|
113 | routeIndex?: number;
|
114 | suppressBicyclingLayer?: boolean;
|
115 | suppressInfoWindows?: boolean;
|
116 | suppressMarkers?: boolean;
|
117 | suppressPolylines?: boolean;
|
118 | }
|
119 |
|
120 | /**
|
121 | * A DirectionsWaypoint represents a location between origin and destination
|
122 | * through which the trip should be routed.
|
123 | * @see {@link https://developers.google.com/maps/documentation/javascript/reference/directions#DirectionsWaypoint Maps JavaScript API}
|
124 | */
|
125 | interface DirectionsWaypoint {
|
126 | /**
|
127 | * Waypoint location. Can be an address string, a {@link LatLng}, or a
|
128 | * {@link Place}.
|
129 | * @see {@link https://developers.google.com/maps/documentation/javascript/reference/directions#DirectionsWaypoint.location Maps JavaScript API}
|
130 | */
|
131 | location?: string | LatLng | Place;
|
132 | /**
|
133 | * If `true`, indicates that this waypoint is a stop between the origin and
|
134 | * destination. This has the effect of splitting the route into two legs. If
|
135 | * `false`, indicates that the route should be biased to go through this
|
136 | * waypoint, but not split into two legs. This is useful if you want to
|
137 | * create a route in response to the user dragging waypoints on a map.
|
138 | * @default true
|
139 | * @see {@link https://developers.google.com/maps/documentation/javascript/reference/directions#DirectionsWaypoint.stopover Maps JavaScript API}
|
140 | */
|
141 | stopover?: boolean;
|
142 | }
|
143 |
|
144 | /**
|
145 | * A single geocoded waypoint.
|
146 | */
|
147 | interface DirectionsGeocodedWaypoint {
|
148 | partial_match: boolean;
|
149 | place_id: string;
|
150 | types: string[];
|
151 | }
|
152 |
|
153 | /**
|
154 | * A single route containing a set of legs in a DirectionsResult.
|
155 | * Note that though this object is "JSON-like," it is not strictly JSON,
|
156 | * as it directly and indirectly includes LatLng objects.
|
157 | */
|
158 | interface DirectionsRoute {
|
159 | /** The bounds for this route. */
|
160 | bounds: LatLngBounds;
|
161 | /** Copyrights text to be displayed for this route. */
|
162 | copyrights: string;
|
163 | /**
|
164 | * The total fare for the whole transit trip. Only applicable to transit
|
165 | * requests.
|
166 | */
|
167 | fare: TransitFare;
|
168 | /**
|
169 | * An array of DirectionsLegs, each of which contains information about the
|
170 | * steps of which it is composed. There will be one leg for each stopover
|
171 | * waypoint or destination specified. So a route with no stopover waypoints
|
172 | * will contain one DirectionsLeg and a route with one stopover waypoint
|
173 | * will contain two.
|
174 | */
|
175 | legs: DirectionsLeg[];
|
176 | /**
|
177 | * An array of LatLngs representing the entire course of this route. The
|
178 | * path is simplified in order to make it suitable in contexts where a small
|
179 | * number of vertices is required (such as Static Maps API URLs).
|
180 | */
|
181 | overview_path: LatLng[];
|
182 | /**
|
183 | * An encoded polyline representation of the route in overview_path.
|
184 | * This polyline is an approximate (smoothed) path of the resulting
|
185 | * directions.
|
186 | */
|
187 | overview_polyline: string;
|
188 | /** Warnings to be displayed when showing these directions. */
|
189 | warnings: string[];
|
190 | /**
|
191 | * If optimizeWaypoints was set to true, this field will contain the
|
192 | * re-ordered permutation of the input waypoints. For example, if the input
|
193 | * was: Origin: Los Angeles Waypoints: Dallas, Bangor, Phoenix Destination:
|
194 | * New York and the optimized output was ordered as follows: Origin: Los
|
195 | * Angeles Waypoints: Phoenix, Dallas, Bangor Destination: New York then
|
196 | * this field will be an Array containing the values [2, 0, 1]. Note that
|
197 | * the numbering of waypoints is zero-based. If any of the input waypoints
|
198 | * has stopover set to false, this field will be empty, since route
|
199 | * optimization is not available for such queries.
|
200 | */
|
201 | waypoint_order: number[];
|
202 | }
|
203 |
|
204 | interface DirectionsLeg {
|
205 | arrival_time: Time;
|
206 | departure_time: Time;
|
207 | distance: Distance;
|
208 | duration: Duration;
|
209 | duration_in_traffic: Duration;
|
210 | end_address: string;
|
211 | end_location: LatLng;
|
212 | start_address: string;
|
213 | start_location: LatLng;
|
214 | steps: DirectionsStep[];
|
215 | via_waypoints: LatLng[];
|
216 | }
|
217 |
|
218 | // TODO find source documentation
|
219 | interface BaseDirectionsStep {
|
220 | distance: Distance;
|
221 | duration: Duration;
|
222 | end_location: LatLng;
|
223 | instructions: string;
|
224 | path: LatLng[];
|
225 | start_location: LatLng;
|
226 | transit: TransitDetails;
|
227 | travel_mode: TravelMode;
|
228 | }
|
229 |
|
230 | interface DirectionsStep extends BaseDirectionsStep {
|
231 | /**
|
232 | * This field will only be available if travel_mode is set to TRANSIT.
|
233 | */
|
234 | steps: BaseDirectionsStep[];
|
235 | }
|
236 |
|
237 | interface Place {
|
238 | location?: LatLng | LatLngLiteral;
|
239 | placeId?: string;
|
240 | query?: string;
|
241 | }
|
242 |
|
243 | enum TravelMode {
|
244 | BICYCLING = 'BICYCLING',
|
245 | DRIVING = 'DRIVING',
|
246 | TRANSIT = 'TRANSIT',
|
247 | TWO_WHEELER = 'TWO_WHEELER',
|
248 | WALKING = 'WALKING',
|
249 | }
|
250 |
|
251 | interface DrivingOptions {
|
252 | departureTime: Date;
|
253 | trafficModel?: TrafficModel;
|
254 | }
|
255 |
|
256 | enum TrafficModel {
|
257 | BEST_GUESS = 'bestguess',
|
258 | OPTIMISTIC = 'optimistic',
|
259 | PESSIMISTIC = 'pessimistic',
|
260 | }
|
261 |
|
262 | interface TransitOptions {
|
263 | arrivalTime?: Date;
|
264 | departureTime?: Date;
|
265 | modes?: TransitMode[];
|
266 | routingPreference?: TransitRoutePreference;
|
267 | }
|
268 |
|
269 | enum TransitMode {
|
270 | BUS = 'BUS',
|
271 | RAIL = 'RAIL',
|
272 | SUBWAY = 'SUBWAY',
|
273 | TRAIN = 'TRAIN',
|
274 | TRAM = 'TRAM',
|
275 | }
|
276 |
|
277 | enum TransitRoutePreference {
|
278 | FEWER_TRANSFERS = 'FEWER_TRANSFERS',
|
279 | LESS_WALKING = 'LESS_WALKING',
|
280 | }
|
281 |
|
282 | interface TransitFare {
|
283 | currency: string;
|
284 | value: number;
|
285 | }
|
286 |
|
287 | interface TransitDetails {
|
288 | arrival_stop: TransitStop;
|
289 | arrival_time: Time;
|
290 | departure_stop: TransitStop;
|
291 | departure_time: Time;
|
292 | headsign: string;
|
293 | headway: number;
|
294 | line: TransitLine;
|
295 | num_stops: number;
|
296 | }
|
297 |
|
298 | interface TransitStop {
|
299 | location: LatLng;
|
300 | name: string;
|
301 | }
|
302 |
|
303 | interface TransitLine {
|
304 | agencies: TransitAgency[];
|
305 | color: string;
|
306 | icon: string;
|
307 | name: string;
|
308 | short_name: string;
|
309 | text_color: string;
|
310 | url: string;
|
311 | vehicle: TransitVehicle;
|
312 | }
|
313 |
|
314 | interface TransitAgency {
|
315 | name: string;
|
316 | phone: string;
|
317 | url: string;
|
318 | }
|
319 |
|
320 | interface TransitVehicle {
|
321 | icon: string;
|
322 | local_icon: string;
|
323 | name: string;
|
324 | type: VehicleType;
|
325 | }
|
326 |
|
327 | enum VehicleType {
|
328 | BUS,
|
329 | CABLE_CAR,
|
330 | COMMUTER_TRAIN,
|
331 | FERRY,
|
332 | FUNICULAR,
|
333 | GONDOLA_LIFT,
|
334 | HEAVY_RAIL,
|
335 | HIGH_SPEED_TRAIN,
|
336 | INTERCITY_BUS,
|
337 | METRO_RAIL,
|
338 | MONORAIL,
|
339 | OTHER,
|
340 | RAIL,
|
341 | SHARE_TAXI,
|
342 | SUBWAY,
|
343 | TRAM,
|
344 | TROLLEYBUS,
|
345 | }
|
346 |
|
347 | enum UnitSystem {
|
348 | METRIC = 0,
|
349 | IMPERIAL = 1,
|
350 | }
|
351 |
|
352 | interface Distance {
|
353 | text: string;
|
354 | value: number;
|
355 | }
|
356 |
|
357 | interface Duration {
|
358 | text: string;
|
359 | value: number;
|
360 | }
|
361 |
|
362 | interface Time {
|
363 | text: string;
|
364 | time_zone: string;
|
365 | value: Date;
|
366 | }
|
367 | }
|