Newer Version Available
Get a Route
The getRoute() Apex method
returns a route between two or more waypoints for the specified mode of transportation.
The travel time depends on the mode of transportation. The route appears in Salesforce Maps for
the users who requested the route, such as a delivery truck driver and the admin. This method
doesn’t optimize the route. Instead, it finds a route between the waypoints in entered sequence.
Signature
1Map<String, Object> maps.API.getRoute(String requestJSON)Where,
- maps is the namespace that's available after you install Salesforce Maps.
- API is the class that contains the global methods exposed to developers.
- getRoute() is the method.
Sample Code
This code finds a route for someone driving a car from one
grocery store to another.
Input Format of the Request JSON String
The input format supports standard and custom drive profiles. If your drivers require routes optimized for vehicles that can't travel on the same roads as cars, create a custom drive profile first, and then add it to your driveProfile string.
1{
2driveProfile: 'string' // Mode of transportation. Standard profile values are 'car' and 'bicycle'. For a custom profile, specify its record ID.
3waypoints: [ {id:String, lat:Decimal, lng:Decimal, id:String}, ... ] // List of waypoints
4hideGeoJSON: boolean // Optional. If set to true, the GeoJSON is excluded from the response
5}Example
1// Create a list of waypoints.
2List<Map<String,Object>> waypoints = new List<Map<String,Object>>();
3waypoints.add(new Map<String,Object>{
4 'lat' => 33.917760,
5 'lng' => -84.379750,
6 'id' => 'groceryNorth'
7});
8
9waypoints.add(new Map<String,Object>{
10 'lat' => 33.840630,
11 'lng' => -84.381920,
12 'id' => 'grocerySouth'
13});
14
15// Build the request.
16Map<String,Object> request = new Map<String,Object>();
17request.put('waypoints',waypoints);
18request.put('driveProfile','car'); // For a custom drive profile, replace 'car' with the ID of your custom drive profile.
19request.put('hideGeoJSON', true); // Optional. Add only if removing the GeoJSON from the response
20String routeRequest = JSON.serialize(request);
21
22// Call the getRoute() method with the waypoints and mode of transportation.
23Map<String,Object> response = maps.API.getRoute(routeRequest);
24
25// Log the resulting route.
26system.debug(response);Sample Response
Although the return value is an Apex Map<String, Object> object, this JSON response illustrates the essential data you receive in the resulting map.
1{
2 "profile": {
3 "width": null,
4 "weightPerAxle": null,
5 "weight": null,
6 "type": "car",
7 "trailers": null,
8 "length": null,
9 "height": null,
10 "hazmat": null,
11 "axles": null
12 },
13 "request": {
14 "profile": {
15 "type": "car"
16 },
17 "timebased": false,
18 "waypoints": [
19 {
20 "id": "groceryNorth",
21 "lat": 33.91776,
22 "lng": -84.37975
23 },
24 {
25 "id": "grocerySouth",
26 "lat": 33.84063,
27 "lng": -84.38192
28 }
29 ]
30 },
31 "response": {
32 "success": true,
33 "geojson": {
34 "features": [
35 {
36 "geometry": {
37 "coordinates": [
38 [
39 [
40 -84.37935,
41 33.91775
42 ],
43 [
44 -84.37935,
45 33.91744
46 ],
47 [
48 -84.37913,
49 33.91743
50 ],
51 [
52 -84.37915,
53 33.91725
54 ],
55 [
56 -84.37916,
57 33.91717
58 ],
59 [
60 -84.37916,
61 33.91704
62 ],
63 [
64 -84.37916,
65 33.91698
66 ],
67 [
68 -84.37919,
69 33.91667
70 ],
71 [
72 -84.37919,
73 33.91661
74 ],
75 [
76 -84.37922,
77 33.91622
78 ],
79 [
80 -84.37923,
81 33.91609
82 ],
83 [
84 -84.37925,
85 33.91601
86 ],
87 [
88 -84.37925,
89 33.91592
90 ],
91 [
92 -84.37928,
93 33.91574
94 ],
95 [
96 -84.37929,
97 33.91558
98 ],
99 [
100 -84.37932,
101 33.91503
102 ],
103 [
104 -84.37932,
105 33.9148
106 ],
107 [
108 -84.37932,
109 33.91461
110 ],
111 [
112 -84.37929,
113 33.91418
114 ],
115 [
116 -84.37928,
117 33.914
118 ],
119 [
120 -84.37925,
121 33.91384
122 ],
123 [
124 -84.37925,
125 33.91371
126 ],
127 [
128 -84.37923,
129 33.91363
130 ],
131 [
132 -84.37922,
133 33.91348
134 ],
135 [
136 -84.37921,
137 33.91323
138 ],
139 [
140 -84.37913,
141 33.91276
142 ],
143 [
144 -84.37907,
145 33.91231
146 ],
147 [
148 -84.37905,
149 33.91212
150 ],
151 [
152 -84.379,
153 33.91167
154 ],
155 [
156 -84.37886,
157 33.9116
158 ],
159 [
160 -84.37871,
161 33.91157
162 ],
163 [
164 -84.37852,
165 33.91157
166 ],
167 [
168 -84.37777,
169 33.91165
170 ],
171 [
172 -84.37728,
173 33.9117
174 ],
175 [
176 -84.37643,
177 33.91176
178 ],
179 [
180 -84.3761,
181 33.91178
182 ],
183 [
184 -84.37571,
185 33.91176
186 ],
187 [
188 -84.37529,
189 33.91171
190 ],
191 [
192 -84.37417,
193 33.91152
194 ],
195 [
196 -84.37369,
197 33.91144
198 ],
199 [
200 -84.37343,
201 33.91139
202 ],
203 [
204 -84.37324,
205 33.91136
206 ],
207 [
208 -84.37313,
209 33.91139
210 ],
211 [
212 -84.37292,
213 33.91144
214 ],
215 [
216 -84.37153,
217 33.91117
218 ],
219 [
220 -84.37092,
221 33.91107
222 ],
223 [
224 -84.36998,
225 33.91088
226 ],
227 [
228 -84.36943,
229 33.91078
230 ],
231 [
232 -84.36906,
233 33.91072
234 ],
235 [
236 -84.36879,
237 33.91067
238 ],
239 [
240 -84.36782,
241 33.91049
242 ],
243 [
244 -84.3675,
245 33.91043
246 ],
247 [
248 -84.36641,
249 33.91025
250 ],
251 [
252 -84.36613,
253 33.91019
254 ],
255 [
256 -84.36534,
257 33.91009
258 ],
259 [
260 -84.3648,
261 33.91004
262 ],
263 [
264 -84.36428,
265 33.90999
266 ],
267 [
268 -84.36374,
269 33.90998
270 ],
271 [
272 -84.36349,
273 33.90999
274 ],
275 [
276 -84.36326,
277 33.91001
278 ],
279 [
280 -84.3631,
281 33.90993
282 ],
283 [
284 -84.363,
285 33.90993
286 ],
287 [
288 -84.36278,
289 33.90993
290 ],
291 [
292 -84.36248,
293 33.90994
294 ],
295 [
296 -84.36225,
297 33.90996
298 ],
299 [
300 -84.36181,
301 33.90999
302 ],
303 [
304 -84.36171,
305 33.90999
306 ],
307 [
308 -84.36162,
309 33.91001
310 ],
311 [
312 -84.36152,
313 33.91001
314 ],
315 [
316 -84.36094,
317 33.91006
318 ],
319 [
320 -84.36046,
321 33.91007
322 ],
323 [
324 -84.36024,
325 33.91007
326 ],
327 [
328 -84.36004,
329 33.91004
330 ],
331 [
332 -84.35985,
333 33.91001
334 ],
335 [
336 -84.35965,
337 33.90994
338 ],
339 [
340 -84.35949,
341 33.90987
342 ],
343 [
344 -84.35931,
345 33.90979
346 ],
347 [
348 -84.35917,
349 33.90969
350 ],
351 [
352 -84.35902,
353 33.90959
354 ],
355 [
356 -84.35888,
357 33.90948
358 ],
359 [
360 -84.35875,
361 33.90936
362 ],
363 [
364 -84.35862,
365 33.90923
366 ],
367 [
368 -84.3585,
369 33.90909
370 ],
371 [
372 -84.3584,
373 33.90894
374 ],
375 [
376 -84.3583,
377 33.90879
378 ],
379 [
380 -84.35821,
381 33.90864
382 ],
383 [
384 -84.35815,
385 33.90845
386 ],
387 [
388 -84.35811,
389 33.90829
390 ],
391 [
392 -84.35801,
393 33.90758
394 ],
395 [
396 -84.35801,
397 33.90731
398 ],
399 [
400 -84.35801,
401 33.90721
402 ],
403 [
404 -84.35804,
405 33.90692
406 ],
407 [
408 -84.3582,
409 33.90634
410 ],
411 [
412 -84.35837,
413 33.90592
414 ],
415 [
416 -84.35853,
417 33.90552
418 ],
419 [
420 -84.3586,
421 33.90531
422 ],
423 [
424 -84.35876,
425 33.90493
426 ],
427 [
428 -84.35901,
429 33.90441
430 ],
431 [
432 -84.35914,
433 33.90417
434 ],
435 [
436 -84.35968,
437 33.9032
438 ],
439 [
440 -84.35975,
441 33.90306
442 ],
443 [
444 -84.36027,
445 33.9022
446 ],
447 [
448 -84.3605,
449 33.9018
450 ],
451 [
452 -84.36052,
453 33.90177
454 ],
455 [
456 -84.36081,
457 33.9013
458 ],
459 [
460 -84.36122,
461 33.90061
462 ],
463 [
464 -84.36133,
465 33.90037
466 ],
467 [
468 -84.36168,
469 33.89976
470 ],
471 [
472 -84.36184,
473 33.89944
474 ],
475 [
476 -84.36229,
477 33.89863
478 ],
479 [
480 -84.36259,
481 33.89807
482 ],
483 [
484 -84.3631,
485 33.89714
486 ],
487 [
488 -84.36326,
489 33.89685
490 ],
491 [
492 -84.36332,
493 33.89672
494 ],
495 [
496 -84.36339,
497 33.8966
498 ],
499 [
500 -84.36342,
501 33.89638
502 ],
503 [
504 -84.36352,
505 33.89619
506 ],
507 [
508 -84.36358,
509 33.89611
510 ],
511 [
512 -84.36397,
513 33.89543
514 ],
515 [
516 -84.36422,
517 33.89503
518 ],
519 [
520 -84.36444,
521 33.89469
522 ],
523 [
524 -84.36448,
525 33.89459
526 ],
527 [
528 -84.36455,
529 33.89445
530 ],
531 [
532 -84.36457,
533 33.8944
534 ],
535 [
536 -84.36465,
537 33.89419
538 ],
539 [
540 -84.36476,
541 33.89395
542 ],
543 [
544 -84.36484,
545 33.89369
546 ],
547 [
548 -84.36493,
549 33.89344
550 ],
551 [
552 -84.365,
553 33.89318
554 ],
555 [
556 -84.36505,
557 33.89292
558 ],
559 [
560 -84.36507,
561 33.89273
562 ],
563 [
564 -84.36509,
565 33.89266
566 ],
567 [
568 -84.36516,
569 33.89215
570 ],
571 [
572 -84.36519,
573 33.89161
574 ],
575 [
576 -84.36519,
577 33.89109
578 ],
579 [
580 -84.36519,
581 33.8908
582 ],
583 [
584 -84.36518,
585 33.88977
586 ],
587 [
588 -84.36516,
589 33.8885
590 ],
591 [
592 -84.36513,
593 33.88722
594 ],
595 [
596 -84.36512,
597 33.88563
598 ],
599 [
600 -84.3651,
601 33.88468
602 ],
603 [
604 -84.36509,
605 33.8842
606 ],
607 [
608 -84.36509,
609 33.88399
610 ],
611 [
612 -84.36507,
613 33.88254
614 ],
615 [
616 -84.36507,
617 33.8813
618 ],
619 [
620 -84.36506,
621 33.88016
622 ],
623 [
624 -84.36507,
625 33.87937
626 ],
627 [
628 -84.36509,
629 33.87882
630 ],
631 [
632 -84.36509,
633 33.87847
634 ],
635 [
636 -84.36509,
637 33.8781
638 ],
639 [
640 -84.3651,
641 33.8773
642 ],
643 [
644 -84.36512,
645 33.87648
646 ],
647 [
648 -84.36507,
649 33.87545
650 ],
651 [
652 -84.36506,
653 33.87501
654 ],
655 [
656 -84.36506,
657 33.87478
658 ],
659 [
660 -84.36503,
661 33.87435
662 ],
663 [
664 -84.365,
665 33.87371
666 ],
667 [
668 -84.36497,
669 33.87306
670 ],
671 [
672 -84.36496,
673 33.87266
674 ],
675 [
676 -84.36497,
677 33.87221
678 ],
679 [
680 -84.36502,
681 33.87197
682 ],
683 [
684 -84.36506,
685 33.87173
686 ],
687 [
688 -84.36515,
689 33.87145
690 ],
691 [
692 -84.36522,
693 33.87123
694 ],
695 [
696 -84.36536,
697 33.87081
698 ],
699 [
700 -84.36547,
701 33.87061
702 ],
703 [
704 -84.36558,
705 33.87037
706 ],
707 [
708 -84.36586,
709 33.86994
710 ],
711 [
712 -84.36635,
713 33.86933
714 ],
715 [
716 -84.36654,
717 33.86912
718 ],
719 [
720 -84.36687,
721 33.86875
722 ],
723 [
724 -84.36741,
725 33.86815
726 ],
727 [
728 -84.36792,
729 33.86754
730 ],
731 [
732 -84.36809,
733 33.86734
734 ],
735 [
736 -84.36824,
737 33.86711
738 ],
739 [
740 -84.36838,
741 33.8669
742 ],
743 [
744 -84.3685,
745 33.86667
746 ],
747 [
748 -84.36863,
749 33.86645
750 ],
751 [
752 -84.36873,
753 33.8662
754 ],
755 [
756 -84.36882,
757 33.86597
758 ],
759 [
760 -84.36889,
761 33.86574
762 ],
763 [
764 -84.36895,
765 33.86548
766 ],
767 [
768 -84.36905,
769 33.86499
770 ],
771 [
772 -84.36912,
773 33.86447
774 ],
775 [
776 -84.36915,
777 33.8641
778 ],
779 [
780 -84.36925,
781 33.86289
782 ],
783 [
784 -84.36937,
785 33.86156
786 ],
787 [
788 -84.36947,
789 33.86029
790 ],
791 [
792 -84.3695,
793 33.85995
794 ],
795 [
796 -84.36954,
797 33.85932
798 ],
799 [
800 -84.36957,
801 33.85893
802 ],
803 [
804 -84.36966,
805 33.85792
806 ],
807 [
808 -84.36969,
809 33.85755
810 ],
811 [
812 -84.36969,
813 33.85752
814 ],
815 [
816 -84.36973,
817 33.85713
818 ],
819 [
820 -84.36976,
821 33.85673
822 ],
823 [
824 -84.3698,
825 33.85618
826 ],
827 [
828 -84.37002,
829 33.85525
830 ],
831 [
832 -84.37008,
833 33.85483
834 ],
835 [
836 -84.37017,
837 33.8543
838 ],
839 [
840 -84.37024,
841 33.85388
842 ],
843 [
844 -84.37027,
845 33.8533
846 ],
847 [
848 -84.37031,
849 33.85279
850 ],
851 [
852 -84.37031,
853 33.8525
854 ],
855 [
856 -84.37034,
857 33.85216
858 ],
859 [
860 -84.37037,
861 33.852
862 ],
863 [
864 -84.3704,
865 33.85192
866 ],
867 [
868 -84.37044,
869 33.85188
870 ],
871 [
872 -84.37056,
873 33.85179
874 ],
875 [
876 -84.37092,
877 33.85168
878 ],
879 [
880 -84.37121,
881 33.85156
882 ],
883 [
884 -84.37134,
885 33.85149
886 ],
887 [
888 -84.37149,
889 33.85138
890 ],
891 [
892 -84.37159,
893 33.85131
894 ],
895 [
896 -84.37169,
897 33.85124
898 ],
899 [
900 -84.37202,
901 33.85092
902 ],
903 [
904 -84.37233,
905 33.85063
906 ],
907 [
908 -84.37311,
909 33.84989
910 ],
911 [
912 -84.37313,
913 33.84986
914 ],
915 [
916 -84.37326,
917 33.84975
918 ],
919 [
920 -84.37347,
921 33.84954
922 ],
923 [
924 -84.37359,
925 33.84943
926 ],
927 [
928 -84.3739,
929 33.8491
930 ],
931 [
932 -84.37407,
933 33.84886
934 ],
935 [
936 -84.37419,
937 33.8487
938 ],
939 [
940 -84.3743,
941 33.84854
942 ],
943 [
944 -84.3741,
945 33.84846
946 ],
947 [
948 -84.37394,
949 33.84836
950 ],
951 [
952 -84.37388,
953 33.84833
954 ],
955 [
956 -84.37378,
957 33.84825
958 ],
959 [
960 -84.37369,
961 33.84817
962 ],
963 [
964 -84.37365,
965 33.84812
966 ],
967 [
968 -84.37362,
969 33.84805
970 ],
971 [
972 -84.37356,
973 33.84799
974 ],
975 [
976 -84.37345,
977 33.84783
978 ],
979 [
980 -84.37337,
981 33.84772
982 ],
983 [
984 -84.37334,
985 33.84765
986 ],
987 [
988 -84.3733,
989 33.84759
990 ],
991 [
992 -84.37329,
993 33.84754
994 ],
995 [
996 -84.37321,
997 33.8474
998 ],
999 [
1000 -84.3731,
1001 33.84715
1002 ],
1003 [
1004 -84.373,
1005 33.84695
1006 ],
1007 [
1008 -84.37278,
1009 33.84651
1010 ],
1011 [
1012 -84.3726,
1013 33.84615
1014 ],
1015 [
1016 -84.3724,
1017 33.84569
1018 ],
1019 [
1020 -84.37233,
1021 33.84556
1022 ],
1023 [
1024 -84.37214,
1025 33.84514
1026 ],
1027 [
1028 -84.37204,
1029 33.84495
1030 ],
1031 [
1032 -84.37192,
1033 33.84474
1034 ],
1035 [
1036 -84.37188,
1037 33.84466
1038 ],
1039 [
1040 -84.37182,
1041 33.84456
1042 ],
1043 [
1044 -84.37166,
1045 33.84423
1046 ],
1047 [
1048 -84.37159,
1049 33.84411
1050 ],
1051 [
1052 -84.37141,
1053 33.84379
1054 ],
1055 [
1056 -84.37146,
1057 33.84376
1058 ],
1059 [
1060 -84.37188,
1061 33.84352
1062 ],
1063 [
1064 -84.37208,
1065 33.84339
1066 ],
1067 [
1068 -84.37224,
1069 33.84329
1070 ],
1071 [
1072 -84.37233,
1073 33.84323
1074 ],
1075 [
1076 -84.37249,
1077 33.84312
1078 ],
1079 [
1080 -84.37259,
1081 33.84304
1082 ],
1083 [
1084 -84.37285,
1085 33.84283
1086 ],
1087 [
1088 -84.37297,
1089 33.84275
1090 ],
1091 [
1092 -84.37304,
1093 33.8427
1094 ],
1095 [
1096 -84.37317,
1097 33.8426
1098 ],
1099 [
1100 -84.37329,
1101 33.84252
1102 ],
1103 [
1104 -84.37343,
1105 33.84241
1106 ],
1107 [
1108 -84.37359,
1109 33.84228
1110 ],
1111 [
1112 -84.37368,
1113 33.84223
1114 ],
1115 [
1116 -84.37414,
1117 33.84191
1118 ],
1119 [
1120 -84.37424,
1121 33.84186
1122 ],
1123 [
1124 -84.3744,
1125 33.84175
1126 ],
1127 [
1128 -84.37449,
1129 33.8417
1130 ],
1131 [
1132 -84.37468,
1133 33.84157
1134 ],
1135 [
1136 -84.37481,
1137 33.84149
1138 ],
1139 [
1140 -84.37507,
1141 33.84135
1142 ],
1143 [
1144 -84.37526,
1145 33.84123
1146 ],
1147 [
1148 -84.37533,
1149 33.8412
1150 ],
1151 [
1152 -84.37562,
1153 33.84106
1154 ],
1155 [
1156 -84.37603,
1157 33.84086
1158 ],
1159 [
1160 -84.37609,
1161 33.84083
1162 ],
1163 [
1164 -84.37616,
1165 33.8408
1166 ],
1167 [
1168 -84.37646,
1169 33.84066
1170 ],
1171 [
1172 -84.37684,
1173 33.84051
1174 ],
1175 [
1176 -84.377,
1177 33.84043
1178 ],
1179 [
1180 -84.3772,
1181 33.84038
1182 ],
1183 [
1184 -84.37736,
1185 33.84035
1186 ],
1187 [
1188 -84.37742,
1189 33.84035
1190 ],
1191 [
1192 -84.37755,
1193 33.84033
1194 ],
1195 [
1196 -84.37771,
1197 33.84032
1198 ],
1199 [
1200 -84.37793,
1201 33.84032
1202 ],
1203 [
1204 -84.37809,
1205 33.84032
1206 ],
1207 [
1208 -84.37828,
1209 33.8403
1210 ],
1211 [
1212 -84.37842,
1213 33.84025
1214 ],
1215 [
1216 -84.37861,
1217 33.84022
1218 ],
1219 [
1220 -84.37878,
1221 33.84011
1222 ],
1223 [
1224 -84.37899,
1225 33.84001
1226 ],
1227 [
1228 -84.37912,
1229 33.83993
1230 ],
1231 [
1232 -84.37921,
1233 33.83988
1234 ],
1235 [
1236 -84.37947,
1237 33.8397
1238 ],
1239 [
1240 -84.37987,
1241 33.83941
1242 ],
1243 [
1244 -84.38009,
1245 33.83946
1246 ],
1247 [
1248 -84.38039,
1249 33.83954
1250 ],
1251 [
1252 -84.38063,
1253 33.83963
1254 ],
1255 [
1256 -84.38074,
1257 33.83969
1258 ],
1259 [
1260 -84.38082,
1261 33.83972
1262 ],
1263 [
1264 -84.38111,
1265 33.83983
1266 ],
1267 [
1268 -84.38116,
1269 33.83987
1270 ],
1271 [
1272 -84.38131,
1273 33.83995
1274 ],
1275 [
1276 -84.38141,
1277 33.84001
1278 ],
1279 [
1280 -84.38169,
1281 33.84014
1282 ],
1283 [
1284 -84.38176,
1285 33.84017
1286 ],
1287 [
1288 -84.38192,
1289 33.84025
1290 ],
1291 [
1292 -84.38183,
1293 33.84043
1294 ],
1295 [
1296 -84.38199,
1297 33.84051
1298 ],
1299 [
1300 -84.38196,
1301 33.84063
1302 ]
1303 ]
1304 ],
1305 "type": "LineString"
1306 },
1307 "properties": {},
1308 "type": "Feature"
1309 }
1310 ],
1311 "type": "FeatureCollection"
1312 },
1313 "waypoints": [
1314 {
1315 "maneuvers": [],
1316 "departuretime": 1619794087,
1317 "start": 1619794087,
1318 "arrivaltime": 1619794087,
1319 "idletime": 0,
1320 "totaltraveltime": 945,
1321 "nontraffictime": 798,
1322 "traffictime": 147,
1323 "distance": 9274,
1324 "duration": 0,
1325 "lng": -84.37975,
1326 "lat": 33.91776,
1327 "id": "groceryNorth",
1328 "success": true
1329 },
1330 {
1331 "maneuvers": [],
1332 "departuretime": 1619795032,
1333 "start": 1619795032,
1334 "arrivaltime": 1619795032,
1335 "idletime": 0,
1336 "totaltraveltime": 0,
1337 "nontraffictime": 0,
1338 "traffictime": 0,
1339 "distance": 0,
1340 "duration": 0,
1341 "lng": -84.38192,
1342 "lat": 33.84063,
1343 "id": "grocerySouth",
1344 "success": true
1345 }
1346 ],
1347 "summary": {
1348 "totaltraveltime": 945,
1349 "nontraffictime": 798,
1350 "traffictime": 147,
1351 "distance": 9274
1352 },
1353 "boundingbox": {
1354 "southwest": {
1355 "lng": -84.38192,
1356 "lat": 33.84063
1357 },
1358 "northeast": {
1359 "lng": -84.37975,
1360 "lat": 33.91776
1361 }
1362 },
1363 "status": "Completed",
1364 "jobid": "mare-routing-11-1619794088.349843-505"
1365 },
1366 "success": true
1367}