# Get Camera

The `MapCamera` object describes the map's current viewport. It does not provide methods to change it: that is the responsibility of a [`MapController`](/v6/usage/programmatic-control/controller.md).

{% embed url="<https://pub.dev/documentation/flutter_map/latest/flutter_map/MapCamera-class.html>" %}

{% hint style="info" %}
The `MapCamera` object also provides access to some other helpful methods that depend on it, such as `pointToLatLng` & `latLngToPoint`.
{% endhint %}

## Usage Inside Of A `FlutterMap` Child

To get the camera from within the context of a `FlutterMap` widget, use `MapCamera.of(context)`.

{% hint style="info" %}
Calling this method in a `build` method will cause the widget to automatically rebuild when the `MapCamera` changes. See [/pages/PHCyJci0lnfcS8LgyvNw#2.-hooking-into-inherited-state](https://docs.fleaflet.dev/v6/usage/programmatic-control/pages/PHCyJci0lnfcS8LgyvNw#2.-hooking-into-inherited-state "mention") for more information.

If this behaviour is unwanted, use [#single-time](#single-time "mention") instead.
{% endhint %}

If this throws a `StateError`, try wrapping the concerned widget in a `Builder`, to ensure the `FlutterMap` widget is parenting the `BuildContext`. If this has no effect, use [#usage-outside-of-fluttermap](#usage-outside-of-fluttermap "mention") instead.

## Usage Outside Of `FlutterMap`

### Single Time

To get the camera from outside the context of the `FlutterMap` widget, you'll need to setup a `MapController` first: see [Control Camera](/v6/usage/programmatic-control/controller.md) > [Control Camera](/v6/usage/programmatic-control/controller.md#usage-outside-of-fluttermap).

Then, use the `.camera` getter.

{% hint style="warning" %}
Avoid using `MapController.of(context).camera` from within the context of `FlutterMap`, as it is redundant and less performant than using `MapCamera.of(context)` directly.
{% endhint %}

### Listen To Changes

{% content-ref url="/pages/sl4eSFK5ZvCyp3fur4r8" %}
[Listen To Events](/v6/usage/programmatic-control/listen-to-events.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fleaflet.dev/v6/usage/programmatic-control/get-camera.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
