> 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/center-a-map-on-the-current-account.md).

# Center a Map on the Current Account

Center an Avonni Leaflet map on each Account's billing coordinates and show a marker for the record a Salesforce user is viewing.

Give a rep a map of the site they are reviewing on an Account record page. Avonni Map reads the open Account's billing coordinates and uses them as the center. A single marker identifies that location.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2FzQuELXsxBYeQnD4A40id%2Fcenter-a-map-on-the-current-account-result.jpg?alt=media" alt="A Leaflet map centered on a single Northwind Traders marker in the Edgewater area of Chicago."><figcaption><p>The activated Lightning test scene uses Northwind Traders as its Account context. Map data © OpenStreetMap contributors.</p></figcaption></figure>

## Before you start

* Use a Salesforce test org with access to Avonni Component Builder and Lightning App Builder.
* Choose two test Accounts with different billing coordinates, such as Atlas Logistics and Northwind Traders. Keep a third Account without coordinates to test the visibility rules.
* Confirm viewers can read both billing coordinate fields and that Leaflet tiles load in your org. See the [Map reference](https://docs.avonnicomponents.com/dynamic-components/components/map.md) for the tile requirements.

## Steps

{% stepper %}
{% step %}

### Set the record context

1. Create a Dynamic Component and set **Target Page Object** to **Account**. For an existing component, open **Settings** in Component Builder and select **Account** there.
2. Add **Map** to the canvas. Under **Properties** > **Content**, set **Type** to **Leaflet** and **Zoom Level** to `13`.
3. Leave **Data Source** set to **Manual** and the locations list empty. This guide uses the center marker.
   {% endstep %}

{% step %}

### Bind the map center to the Account

1. In **Properties**, expand **Map Center Location**.
2. Open the resource selector next to **Latitude**. Choose the current Account's **Billing Latitude** (`$Component.Record.BillingLatitude`).
3. Do the same for **Longitude**, choosing **Billing Longitude** (`$Component.Record.BillingLongitude`).
4. Enable **Display As Marker** and leave its **Type** set to **Default**. Under **Header**, set **Title** to `Account location`.

<figure><img src="https://2532358799-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODPvvv7Cx9Z9RECLn3oV%2Fuploads%2Flut9HxMtfSxK20btAGv6%2Fcenter-a-map-on-the-current-account-settings.jpg?alt=media" alt="Map Center Location with Latitude and Longitude bound to the current Account&#x27;s billing fields and Display As Marker enabled." width="320"><figcaption><p>Both center coordinates come from the current Account.</p></figcaption></figure>
{% endstep %}

{% step %}

### Show the map when both coordinates are available

1. Open **Set Component Visibility** in the Map properties.
2. Set **When to Display Component** to **All Conditions Are Met**.
3. Add a condition on the current Account's **Billing Latitude** with the operator **Is Not Null**. Add a second condition on **Billing Longitude** with the same operator.

A record with a missing coordinate now leaves the map hidden, so viewers avoid an unrelated location.
{% endstep %}

{% step %}

### Save and test on an Account record page

1. Save and activate the Dynamic Component. In Lightning App Builder, place it on a test **Account Record Page**, then save and activate the page for your test audience.
2. Check the stored coordinates of Atlas Logistics and Northwind Traders in Salesforce. This example uses `41.8786, -87.6359` and `41.9802, -87.6684`, respectively.
3. Open Atlas Logistics on the activated page. Check that the map starts with its single marker at the recorded site. Open Northwind Traders on the same page layout and verify that the center and marker move to the other site.
4. Open the Account without billing coordinates. The map should be hidden. Return to a complete Account and confirm it reappears.
   {% endstep %}
   {% endstepper %}

## Troubleshooting

* **The map is missing on every record.** Check **Target Page Object**, the two field bindings and the viewer's read access. Test on the activated Account record page so the component receives a record.
* **Every record shows the same location.** Make sure both center settings use current-record resources. Compare the stored coordinates on two Accounts and check that the test page uses the activated component version.

## Related tutorials

* [Target Page Object](https://docs.avonnicomponents.com/dynamic-components/core-concepts/target-page-object.md) explains how an Account record page supplies context to a Dynamic Component.
* [Component Visibility](https://docs.avonnicomponents.com/dynamic-components/core-concepts/component-visibility.md) explains how to handle other missing inputs.
* [Map Accounts by Industry](https://docs.avonnicomponents.com/dynamic-components/tutorials/components/map/map-accounts-by-industry.md) plots a group of Account records on a shared map.


---

# 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/center-a-map-on-the-current-account.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.
