---
title: "capture-coordinates"
description: "Capture the user’s current GPS location and show it on a map."
permalink: /docs/runtime/all-ui-components/capture-coordinates/
---
# capture-coordinates

<RuntimeVersion updatedSince="4.82.0" />

## Overview

The `capture-coordinates` component allows users to capture their current location. The captured location will be displayed on a map with a marker.

### Light Mode

![](./media/spaces-2f9tchlr67elhbojpvhhud-2fuploads-2fgit-blob-d0322a4c66f6f4805a1332af37cbac87bcdf6c78-2fcapture-coordinates-light-366956b2.png)

### Dark Mode

![](./media/spaces-2f9tchlr67elhbojpvhhud-2fuploads-2fgit-blob-6928fe17f813021df7313b4015e1830bd37a3084-2fcapture-coordinates-dark-18fc3276.png)

### Basic Examples

#### Capture coordinates & markers

The following example shows how GPS location capturing can show a mix between `marker-query` and `marker` nodes.

In the example the captured location will be bound to the variable specified in the `capture-coordinates` `bind` attribute. Markers are simply locations that are being visually highlighted on a map. This is useful to, for example, show where the captured location is in relation to other points of interest.

```xml
<var name="current_location" type="location" />
<var name="markers" type="query:location" />

<capture-coordinates bind="current_location">
    <marker label="You are here" bind="current_location" icon="fa-home" />
    <marker-query query="markers" latitude="{location.latitude}" longitude="{location.longitude}" label="This is an example label" />
</capture-coordinates>
```

#### "Foreground" Capturing

The following example shows how GPS location capturing can be performed in the "foreground" i.e. the user sees a map showing how their GPS location is captured.

```xml
<var name="current_location" type="location" />
<capture-coordinates label="My Location" bind="current_location" required="false" />
```

#### "Background" Capturing

Using the `show-if` configuration option, it is also possible to capture a GPS location in the background (i.e. the map pictured in the screenshot above is not shown)

```xml
<var name="current_location" type="location" />
<capture-coordinates show-if="false" bind="current_location" required="false" />
```

## Standard Attributes

### `bind`

<SyntaxCard type={"location"} defaultValue={"unset"} required />

The `capture-coordinates` component uses the GPS location of the device and sets this value on the `bind` variable/field. This value will update as accuracy increases of the device's GPS location. A marker will autogenerate at the bound location if no `<marker />` or `<marker-query />` is defined. See [show-markers](#show-markers) for more information on hiding markers.

<Info>

Must be a variable or field of type `location`. See the reference on [data model fields](/docs/data-model/model/field/) for more details.

</Info>

```xml
<var name="current_location" type="location" />

<capture-coordinates bind="current_location" />
```

## Advanced Attributes

### `align-controls`

<SyntaxCard type={["center","left","right"]} defaultValue={"left"} introduced="4.86.1" />

Specify the alignment of the map’s controls. **Note**: controls are visible when the [`allow-zoom`](#allow-zoom) or [`allow-dragging`](#allow-dragging) attributes are enabled.

**main.view\.xml**

```xml
<columns>
    <column>
        <info>align-controls="center"</info>
        <capture-coordinates align-controls="center" allow-zoom="true" allow-dragging="true" label="">
            <marker label="" latitude="39.7392" longitude="-104.9903" />
        </capture-coordinates>            
    </column>
    <column>
        <info>align-controls="left"</info>
        <capture-coordinates align-controls="left" allow-zoom="true" allow-dragging="true" label="">
            <marker label="" latitude="39.7392" longitude="-104.9903" />
        </capture-coordinates>
    </column>
    <column>
        <info>align-controls="right"</info>
        <capture-coordinates align-controls="right" allow-zoom="true" allow-dragging="true" label="">
            <marker label="" latitude="39.7392" longitude="-104.9903" />
        </capture-coordinates>
    </column>
</columns>
```

![](./media/spaces-2f9tchlr67elhbojpvhhud-2fuploads-2f7vjx5zgqalbeq2m41ido-2fimage-5faaee7a.png)

### `allow-dragging`

<SyntaxCard type={"boolean"} defaultValue={"false"} introduced="4.82.0" />

Allow panning the map through touch gestures or mouse click-and-drag movements.

```xml
<var name="current_location" type="location" />

<capture-coordinates bind="current_location" allow-dragging="true" />
```

### `allow-zoom`

<SyntaxCard type={"boolean"} defaultValue={"false"} introduced="4.82.0" />

Display the zoom controls on the component and allow changing the zoom level of the map with touch gestures or by scrolling.

### capture-coordinates

**main.view\.xml**

```xml
<var name="current_location" type="location" />

<capture-coordinates bind="current_location" allow-zoom="true" />
```

### display-coordinates

**main.view\.xml**

```xml
<var name="current_location" type="location" />

<display-coordinates bind="current_location" allow-zoom="true" />
```

### `height`

<SyntaxCard type={"integer"} defaultValue={"500"} />

Specify the height (in pixel) of the `capture-coordinates` / `display-coordinates` component.

### capture-coordinates

**main.view\.xml**

```xml
<var name="current_location" type="location" />

<capture-coordinates bind="current_location" height="500" />
```

### display-coordinates

**main.view\.xml**

```xml
<var name="current_location" type="location" />

<display-coordinates bind="current_location" height="500" />
```

### `on-location`

<SyntaxCard defaultValue={"unset"} introduced="4.82.0" />

**Triggered when**: The user selects a location within the map

**Event parameter**: `$value`

**Return value**: Location object containing the latitude and longitude

`on-location` is an event that calls a JS/TS [`$:function`](/docs/get-started/syntax/expressions-and-events/) or [navigation](/docs/runtime/view-navigation/). See more details:

- [Expressions and Events](/docs/get-started/syntax/expressions-and-events/#call-functions-from-events)

**main.view\.xml**

```xml
<var name="current_location" type="location" />

<capture-coordinates bind="current_location" on-location="$:onLocation($value)"/> />
```

**main.js**

```javascript
function onLocation(location) {
    console.log(location);
    // Example:
    // Object{latitude: 39.7553694, longitude: -105.0195773}
}
```

<Info>

Set `allow-zoom` and `allow-dragging` to `true` to allow users to navigate to different locations on the map.

</Info>

### `show-markers`

<SyntaxCard type={"boolean"} defaultValue={"true"} />

Show or hide all the markers on the map. `show-if`/`hide-if` on individual markers is also available.

### capture-coordinates

**main.view\.xml**

```xml
<var name="current_location" type="location" />

<capture-coordinates bind="current_location" show-markers="false" />
```

### display-coordinates

**main.view\.xml**

```xml
<var name="current_location" type="location" />

<display-coordinates bind="current_location" show-markers="false" />
```

### `align-content`

<AttributeReference label="align-content" href="/docs/runtime/common-component-attributes/align-content/" badge="advanced" tone="muted" />

### `align-label`

<AttributeReference label="align-label" href="/docs/runtime/common-component-attributes/align-label/" badge="advanced" tone="muted" />

### `label-case`

<AttributeReference label="label-case" href="/docs/runtime/common-component-attributes/label-case/" badge="advanced" tone="muted" />

### `label-color`

<AttributeReference label="label-color" href="/docs/runtime/common-component-attributes/label-color/" badge="advanced" tone="muted" />

### `id`

<AttributeReference label="id" href="/docs/runtime/common-component-attributes/id/" badge="advanced" tone="muted" />

### `on-change`

<AttributeReference label="on-change" href="/docs/runtime/common-component-attributes/on-change/" badge="advanced" tone="muted" />

### `show-if`

<AttributeReference label="show-if" href="/docs/runtime/common-component-attributes/show-if/" badge="advanced" tone="muted" />

### `hide-if`

<AttributeReference label="hide-if" href="/docs/runtime/common-component-attributes/hide-if/" badge="advanced" tone="muted" />

## Common Attributes

### `label`

<AttributeReference label="label" href="/docs/runtime/common-component-attributes/label/" />

### `required`

<AttributeReference label="required" href="/docs/runtime/common-component-attributes/required/" />

## Component Methods

The following component methods are available when an [`id`](/docs/runtime/common-component-attributes/id/) is assigned to the component and `component.captureCoordinates({id:'my-id'})` / `component.displayCoordinates({id:'my-id'})` is called from JS/TS:

### `getMapState`

<RuntimeVersion since="4.82.0" />

Programmatically retrieve the current state of the map which will contain the current center and zoom position of the map.

### capture-coordinates

**main.view\.xml**

```xml
<capture-coordinates id="my-id" bind="current_location" />
```

**main.js**

```javascript
try{
  component.captureCoordinates({id: 'my-id'}).getMapState();
}catch (e) {
  // handle exception here
}
```

### display-coordinates

**main.view\.xml**

```xml
<display-coordinates id="my-id" bind="current_location" />
```

**main.js**

```javascript
try{
  component.displayCoordinates({id: 'my-id'}).getMapState();
}catch (e) {
  // handle exception here
}
```

### `setMapState`

<RuntimeVersion since="4.82.0" />

Programmatically set the center and/or zoom position of the map to a specific value.

### capture-coordinates

**main.view\.xml**

```xml
<capture-coordinates id="my-id" bind="current_location" />
```

**main.js**

```javascript
try{
  component.captureCoordinates({id: 'my-id'}).setMapState({
    zoom: 12,
    center: new Location({longitude: -33.00, latitude: -10.00})
  });
}catch (e) {
  // handle exception here
}
```

### display-coordinates

**main.view\.xml**

```xml
<display-coordinates id="my-id" bind="current_location" />
```

**main.js**

```javascript
try{
  component.displayCoordinates({id: 'my-id'}).setMapState({
    zoom: 12,
    center: new Location({longitude: -33.00, latitude: -10.00})
  });
}catch (e) {
  // handle exception here
}
```

### `scrollIntoView`

Programmatically scroll until the `capture-coordinates` component is visible in the view.
