> For the complete documentation index, see [llms.txt](https://docs.avonnicomponents.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/plan-a-multi-stop-visit-route.md).

# Plan a Multi-Stop Visit Route

Query Salesforce Accounts for a Chicago customer visit, pick stops from the map, calculate the driving route, and export the itinerary.

A Chicago account rep is planning quarterly check-ins with customers. On a Lightning page, Avonni Map loads Chicago customer sites from a Salesforce **Account** query. The rep picks today’s stops from the returned sites, calculates the drive, and exports the itinerary to share with the team.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FJ4Q0AhNTNP5Rj6G6JSW8%2Fvisit-route-result.jpg?alt=media" alt="Five numbered Chicago account markers joined by a driving route, with the five account names in the Route panel."><figcaption><p>Each marker represents a Salesforce Account returned by the query. The numbered stops show the visits selected for this drive. Map data © OpenStreetMap contributors.</p></figcaption></figure>

## Before you start

* Use an Avonni Dynamic Component that you can save and test on a Lightning page.
* Ask your administrator to [enable map routing](https://docs.avonnicomponents.com/dynamic-components/components/map/enable-map-routing.md) and confirm that your test user can calculate routes. For Leaflet tiles and settings, see [Map](https://docs.avonnicomponents.com/dynamic-components/components/map.md).
* Use existing Salesforce Accounts with **Billing City** set to `Chicago` and populated billing coordinates. To reproduce the example, use the five sample Accounts below. Enter the coordinates on the Salesforce records. Assign their **Account Number** values `AVMAP-CMpg-01` through `AVMAP-CMpg-05` in table order if you want to isolate the sample records with the same filter shown in the Builder.

| Account Name      | Billing Latitude | Billing Longitude |
| ----------------- | ---------------: | ----------------: |
| Atlas Logistics   |          41.8786 |          -87.6359 |
| Blue Finch Retail |          41.9214 |          -87.6489 |
| Northwind Traders |          41.9802 |          -87.6684 |
| Redwood Supply Co |          41.8579 |          -87.6593 |
| Juniper Health    |          41.7943 |          -87.5907 |

## Steps

{% stepper %}
{% step %}

### Query the Chicago customer sites

1. Add **Map** in Component Builder. In **Properties** > **Content**, set **Type** to **Leaflet**.
2. In **Data Source**, choose **Query**. Under **Records**, create an **Account** query called `Chicago Accounts`.
3. In the query’s **Filters**, set **Take Action When** to **All Conditions Are Met**. Add **Billing City** **Equals** `Chicago`. Add **Billing Latitude** and **Billing Longitude** conditions with **Not equals** and select **Global Constants** > **Null** for each.
4. If you used the sample Account Numbers, add **Account Number** **LIKE** `AVMAP-CMpg-%` to limit the results to those records. Save the query and confirm that `Chicago Accounts` appears under **Records**.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FiG3y4cVAKtMt3Vd9C2d4%2Fvisit-route-account-query.jpg?alt=media" alt="The Account query in Component Builder filters to Chicago and requires both billing coordinates. An Account Number prefix limits the example to its sample records." width="320"><figcaption><p>Billing City limits the map to Chicago. The Account Number prefix keeps the demo separate from other Chicago records.</p></figcaption></figure>
{% endstep %}

{% step %}

### Map the query fields to customer sites

1. In **Data Mappings**, map **Title** to `Name` and **Value** to `Id`.
2. Under **Location**, map **Latitude** to `BillingLatitude`, **Longitude** to `BillingLongitude`, and **City** to `BillingCity`.
3. Set **Header** > **Title** to `Customer visits`. For the sample, set **Content** > **Zoom Level** to `11` and use `41.86`, `-87.64` as the **Map Center Location** to frame Chicago. The query supplies each marker’s position.
   {% endstep %}

{% step %}

### Open the Route panel on load

1. In **Route**, turn on **Show Route Panel** and **Opened by Default**.
2. Keep **Position** set to **Right** and turn on **Display Overlaid on the Map**.
3. Keep **Disable Multi-Stop Selection** off to retain the option to select stops by area.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FFNdPpcUiHmsIflTgqmTR%2Fvisit-route-settings.jpg?alt=media" alt="The Map properties panel with Show Route Panel, Display Overlaid on the Map, and Opened by Default turned on, and Position set to Right." width="320"><figcaption><p>Open the Route panel on the map when the page loads.</p></figcaption></figure>
{% endstep %}

{% step %}

### Pick the stops in visit order

Save and activate the Dynamic Component. Place it on a test Lightning page, then save, activate, and open that page. With the **Route** panel open, choose the Accounts you want to visit today. To reproduce the example, click the five markers in the order listed above. Each stop gets a number on the map and a row in the panel. The first stop is the start of the itinerary. To set a separate origin, use **Starting point**.

Drag a row to change the visit order. If **Optimize** is available, it suggests an order while keeping the starting point or first stop in place. The component can suggest an order by proximity when provider optimization is unavailable. Keep the order above for the first test so you can check it against the source list.
{% endstep %}

{% step %}

### Calculate and export the itinerary

Click **Calculate route**. After the driving route appears, choose **Export the route as a CSV** beside **Calculate route**. The menu on each stop opens that destination in **Google Maps** or **Waze**.
{% endstep %}

{% step %}

### Save and test

1. On the Lightning page, compare the map markers with the Accounts that match the query. Check that the numbered route follows the order you selected. Check for the calculated road line and leg results before using the itinerary. Arrival times depend on the routing provider. If the panel flags stops past the end of the day, review your timing or remove a stop.
2. Open the downloaded CSV. Confirm that **Record Name** lists the five accounts in the same order and **City** is `Chicago` for every row. The navigation links should point to each account's mapped coordinates.
3. Open the menu for **Juniper Health**, choose **Remove**, then calculate and export again. Confirm that the new file has four rows, with **Redwood Supply Co** last.
4. Click **Clear**. The stops and route line should disappear while the account markers remain.
   {% endstep %}
   {% endstepper %}

## Troubleshooting

<details>

<summary>The Route group shows an enablement message</summary>

Confirm that the map uses **Leaflet** and ask your administrator to check the provider connection and the test user's route permission. See [Enable Map Routing](https://docs.avonnicomponents.com/dynamic-components/components/map/enable-map-routing.md).

</details>

<details>

<summary>The map shows straight lines between stops</summary>

Straight lines preview the selected stop order. Use **Calculate route** to request driving directions. If the request fails, check the error message before sharing the plan.

</details>

## Related tutorials

* [Map Accounts by Industry](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/map-accounts-by-industry.md) shows how to distinguish the accounts by sector.
* [Draw and Save a Sales Territory](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/draw-and-save-a-sales-territory.md) uses the same accounts to outline a coverage area.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/plan-a-multi-stop-visit-route.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
