1// Create a list of waypoints.
2List<Map<String,Object>> waypoints = new List<Map<String,Object>>();
3
4// Retrieve the list of billing addresses from the database and
5// add them to the waypoints object.
6List<Account> accountList = [Select Id,BillingStreet,BillingCity,BillingState,BillingPostalcode, BillingLatitude,BillingLongitude From Account Where BillingCity = 'Atlanta' LIMIT 25];
7
8for(Integer i = 0; i < accountList.size(); i++){
9 Account thisAccount = accountList[i];
10 String address = thisAccount.BillingCity + ', ' + thisAccount.BillingState + ' ' + thisAccount.BillingPostalCode;
11 waypoints.add(new Map<String,Object>{
12 'lat' => thisAccount.BillingLatitude,
13 'lng' => thisAccount.BillingLongitude,
14 'address' => address,
15 'recordId' => thisAccount.id,
16 'baseobjectid' => 'a0N0t000002hEyvEAE',
17 'markerlayerid' => 'a0v0t000001wE91AAE',
18 'order' => i + 1
19 });
20}
21
22// Build the request.
23Map<String,Object> request = new Map<String,Object>();
24request.put('version','1');
25request.put('name','Atlanta Accounts Route');
26request.put('waypoints',waypoints);
27
28// Call the CreateRoute() method with the waypoints.
29maps__Route__c response = maps.API.CreateRoute(request);
30
31// Log the route record output in JSON format.
32system.debug(JSON.serialize(response));