> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# `<map>` 4.5 experimental {#map}

APISummary
The `<map>` element embeds a native map. Place a `<map-marker>` directly inside it to anchor Lynx content to a geographic coordinate. Add the map package to each native host and use the same ReactLynx component across platforms.

A `<map-marker>` stays at its `position` as the user pans or zooms. Give the marker a width and height, and use its Lynx children to draw its content. 4.5 experimental

## Add a marker

Give the map a height. Both `center` and `position` take coordinates in degrees. The marker's `anchor` identifies the point within its bounds that sits on the coordinate. For example, `[0.5, 0.5]` centers the label there.

**This is an example below: map**

**Bundle:** `dist/main.lynx.bundle`

```tsx
// Copyright 2026 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { useEffect, useRef, useState } from "@lynx-js/react";
import type { NodesRef } from "@lynx-js/types";

import "./App.css";
import { overview, stops } from "./stops.js";

function PhotoMarker({ stop, selected, onSelect }: {
  stop: (typeof stops)[number];
  selected: boolean;
  onSelect: () => void;
}) {
  const marker = useRef<NodesRef>(null);
  const [photoLoaded, setPhotoLoaded] = useState(false);
  // Providers that draw bitmap markers need a new snapshot after their content changes.
  useEffect(() => {
    if (photoLoaded) {
      marker.current?.invoke({ method: "refreshMarker" }).exec();
    }
  }, [photoLoaded, selected]);

  // Offset the labels for nearby stops while keeping their tips on the coordinates.
  const anchorX = stop.anchorX ?? 0.5;
  return (
    <map-marker
      ref={marker}
      className="marker"
      position={stop.coordinate}
      anchor={[anchorX, 1]}
      bindclickmarker={onSelect}
    >
      <view className="pin-tip" style={{ left: `${anchorX * 100}%` }} />
      <view className={selected ? "pin selected" : "pin"}>
        <image className="pin-photo" src={stop.photo} mode="aspectFill" bindload={() => setPhotoLoaded(true)} />
        <text className={selected ? "pin-name light" : "pin-name"}>{stop.name}</text>
      </view>
    </map-marker>
  );
}

export function App() {
  const [selected, setSelected] = useState<number | null>(null);
  const place = selected === null ? overview : stops[selected];

  return (
    <view className="page">
      <view className="heading">
        <text className="title">San Francisco waterfront</text>
        <text className="hint">Tap a photo pin to explore one of the five stops.</text>
      </view>
      <map className="map" center={place.coordinate} scale={selected === null ? 13.4 : 15}>
        {stops.map((stop, index) => (
          <PhotoMarker
            key={stop.name}
            stop={stop}
            selected={selected === index}
            onSelect={() => setSelected(index)}
          />
        ))}
      </map>
      <view className="detail">
        <image className="detail-photo" src={place.photo} mode="aspectFill" />
        <view className="detail-copy">
          <text className="place-name">{place.name}</text>
          <text className="description">{place.description}</text>
          <view className="actions">
            {selected !== null && (
              <view className="button" bindtap={() => setSelected(null)}>
                <text className="button-label">All stops</text>
              </view>
            )}
            <view
              className="button primary"
              bindtap={() => setSelected(selected === null ? 0 : (selected + 1) % stops.length)}
            >
              <text className="button-label light">{selected === null ? "Start at Pier 39" : "Next stop"} →</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  );
}

```

v0.0.1



Tap one of the five photo markers to center the map and see the landmark up close. Choose **Next stop** to continue along the waterfront or **All stops** to return to the overview. Scan the QR code with a Lynx Explorer build that includes the native map provider.

## `<map>` attributes

### `center`

Android
iOS
Harmony
4.5

```tsx
center?: LatLng;

interface LatLng {
  latitude: number;
  longitude: number;
}
```

Geographic coordinate at the center of the map, in degrees.

### `scale`

Android
iOS
Harmony
4.5

```tsx
scale?: number;
```

Camera zoom level. A larger value zooms in.

### `enable-scale`

Android
iOS
Harmony
4.5

```tsx
'enable-scale'?: boolean;
```

Allow pinch-to-zoom gestures.

### `enable-drag`

Android
iOS
Harmony
4.5

```tsx
'enable-drag'?: boolean;
```

Allow the user to pan the map.

### `enable-rotate`

Android
iOS
Harmony
4.5

```tsx
'enable-rotate'?: boolean;
```

Allow the user to rotate the map.

### `enable-tilt`

Android
iOS
Harmony
4.5

```tsx
'enable-tilt'?: boolean;
```

Allow the user to tilt the camera with a gesture.

## `<map>` events

### `bindmapload`

Android
iOS
Harmony
4.5

```tsx
bindmapload?: (e: BaseEvent<'mapload'>) => void;
```

Fires when the native map finishes loading.

## `<map>` methods

Call these methods using [NodesRef.invoke](/next/api/lynx-api/nodes-ref/nodes-ref-invoke.md). The examples select a map with `id="waterfront"`.

### `setCenter`

Android
iOS
Harmony
4.5

```ts
lynx
  .createSelectorQuery()
  .select('#waterfront')
  .invoke({
    method: 'setCenter',
    params: {
      center: { latitude: 37.7914, longitude: -122.3904 },
      scale: 16,
      animated: false,
    },
  })
  .exec();
```

Move the camera to a geographic coordinate. Pass `scale` to change the zoom level in the same call.

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| `center` | `LatLng` | No | – | Android iOS Harmony 4.5 | 4.5 | New camera center, in degrees. |
| `scale` | `number` | Yes | – | Android iOS Harmony 4.5 | 4.5 | Zoom level to apply with the new center. |
| `animated` | `boolean` | Yes | `true` | Android iOS Harmony 4.5 | 4.5 | Whether to animate the camera movement. Set to `false` to move immediately. |
| `duration` | `number` | Yes | `250` | Android iOS Harmony 4.5 | 4.5 | Animation duration in milliseconds. |

### `getCenter`

Android
iOS
Harmony
4.5

```ts
lynx
  .createSelectorQuery()
  .select('#waterfront')
  .invoke({
    method: 'getCenter',
    success({ latitude, longitude }) {
      console.log(latitude, longitude);
    },
  })
  .exec();
```

Read the current map center. The `success` callback receives both coordinates in degrees.

| Field       | Type     | Optional | Description                              |
| ----------- | -------- | -------- | ---------------------------------------- |
| `latitude`  | `number` | No       | Latitude of the map center, in degrees.  |
| `longitude` | `number` | No       | Longitude of the map center, in degrees. |

### `setScale`

Android
iOS
Harmony
4.5

```ts
lynx
  .createSelectorQuery()
  .select('#waterfront')
  .invoke({
    method: 'setScale',
    params: { scale: 16, animated: true, duration: 400 },
  })
  .exec();
```

Change the zoom level while keeping the current map center.

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| `scale` | `number` | No | – | Android iOS Harmony 4.5 | 4.5 | Target zoom level. |
| `animated` | `boolean` | Yes | `true` | Android iOS Harmony 4.5 | 4.5 | Whether to animate the camera movement. Set to `false` to move immediately. |
| `duration` | `number` | Yes | `250` | Android iOS Harmony 4.5 | 4.5 | Animation duration in milliseconds. |

### `getScale`

Android
iOS
Harmony
4.5

```ts
lynx
  .createSelectorQuery()
  .select('#waterfront')
  .invoke({
    method: 'getScale',
    success({ scale }) {
      console.log(scale);
    },
  })
  .exec();
```

Read the current zoom level in the `success` callback.

| Field   | Type     | Optional | Description                |
| ------- | -------- | -------- | -------------------------- |
| `scale` | `number` | No       | Current camera zoom level. |

## `<map-marker>` attributes

### `position`

Android
iOS
Harmony
4.5

```tsx
position?: LatLng;
```

Geographic coordinate at which to place the marker. Supply both `latitude` and `longitude` in degrees, as for [`center`](#center).

### `anchor`

Android
iOS
Harmony
4.5

```tsx
// @defaultValue: [0.5, 0.5]
anchor?: [number, number];
```

Point on the marker that aligns with its geographic coordinate. The first value runs from left to right and the second from top to bottom, each from 0 to 1. Use `[0.5, 1]` to align the bottom center of a pin.

### `z-index`

Android
iOS
Harmony
4.5

```tsx
'z-index'?: number;
```

Stacking order when markers overlap. A larger value places the marker on top. The Google Maps and HarmonyOS providers default to `1`, and the MapKit provider defaults to `0`.

### `alpha`

Android
iOS
Harmony
4.5

```tsx
// @defaultValue: 1
alpha?: number;
```

Marker opacity, from `0` (transparent) to `1` (opaque).

### `enable-click`

Android
iOS
Harmony
4.5

```tsx
// @defaultValue: true
'enable-click'?: boolean;
```

Allow taps on this marker to fire [`clickmarker`](#bindclickmarker).

## `<map-marker>` events

### `bindclickmarker`

Android
iOS
Harmony
4.5

```tsx
bindclickmarker?: (e: BaseEvent<'clickmarker'>) => void;
```

Fires on the marker the user taps.

## `<map-marker>` methods

Call this method using [NodesRef.invoke](/next/api/lynx-api/nodes-ref/nodes-ref-invoke.md). The example selects a marker with `id="ferry-marker"`.

### `refreshMarker`

Android
iOS
Harmony
4.5

```ts
lynx
  .createSelectorQuery()
  .select('#ferry-marker')
  .invoke({ method: 'refreshMarker' })
  .exec();
```

Refresh the native marker image after changing its Lynx child content. For a photo marker, call this method after the image's `bindload` event so the snapshot includes the photo.

## Host setup

### iOS

Add `XElement/MapImpl` for Apple MapKit. Apps that use `XElement/Behavior` already include it. Register the provider in your app delegate before creating a Lynx view. To use your own provider, depend on `XElement/MapInterface` and register your implementation.

```ruby
pod 'XElement/MapImpl'
```

```objective-c
#import <XElement/LynxMapKitProvider.h>
#import <XElement/LynxXElementMapService.h>

// application:didFinishLaunchingWithOptions:
[LynxXElementMapService registerProvider:[LynxMapKitProvider new]];
```

### Android

Add the XElement behavior bundle and the Google Maps implementation to the app module. Set `lynxVersion` to the SDK version used by the host.

```groovy
dependencies {
    implementation "org.lynxsdk.lynx:xelement:${lynxVersion}"
    implementation "org.lynxsdk.lynx:xelement-map-interface:${lynxVersion}"
    implementation "org.lynxsdk.lynx:xelement-map-impl:${lynxVersion}"
}
```

Register the Google Maps provider in `Application.onCreate()` before initializing Lynx.

```java
import com.lynx.xelement.map.LynxXElementMapService;
import com.lynx.xelement.map.google.GoogleMapProvider;

// Application.onCreate()
LynxXElementMapService.registerProvider(new GoogleMapProvider());
```

Enable Maps SDK for Android in your own Google Cloud project and create an API key for the host app. Restrict it to Maps SDK for Android and to the app's package name and signing certificate SHA-1 fingerprint. [Google Maps SDK setup](https://developers.google.com/maps/documentation/android-sdk/config)

In your app module’s `build.gradle`, pass the key to the manifest at build time. With this setup, set `googleMapsApiKey` in your user-level `~/.gradle/gradle.properties`, or set the `GOOGLE_MAPS_API_KEY` environment variable before building.

```groovy
android {
    defaultConfig {
        manifestPlaceholders.googleMapsApiKey =
            project.findProperty("googleMapsApiKey") ?: System.getenv("GOOGLE_MAPS_API_KEY") ?: ""
    }
}
```

Add the metadata inside `<application>` in `AndroidManifest.xml`. Lynx Explorer already declares the placeholder and accepts the same build settings.

```xml
<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="${googleMapsApiKey}" />
```

Register `builder.addBehaviors(new XElementBehaviors().create())` on your `LynxViewBuilder` before creating the view. Import `com.lynx.xelement.XElementBehaviors`. Run the app on a device or emulator with Google Play services.

### HarmonyOS

Add `@lynx/xelement_map_interface` and `@lynx/xelement_map_impl` to the host module's `oh-package.json5` with versions matching `@lynx/lynx`. Configure Map Kit for your app in AppGallery Connect. [Huawei Map Kit configuration](https://developer.huawei.com/consumer/en/doc/harmonyos-guides/map-config-agc)

Choose the system provider during app initialization. Register both behaviors in the `behaviors` map passed to `LynxView`, alongside your existing behaviors.

```typescript
import { Behavior, BehaviorRegistryMap } from '@lynx/lynx';
import {
  LynxXElementMapService,
  LynxUIMap,
  LynxUIMapMarker,
} from '@lynx/xelement_map_interface';
import { SystemMapProvider } from '@lynx/xelement_map_impl';

LynxXElementMapService.registerProvider(new SystemMapProvider());
const behaviors: BehaviorRegistryMap = new Map([
  ['map', new Behavior(LynxUIMap, undefined)],
  ['map-marker', new Behavior(LynxUIMapMarker, undefined)],
]);
```

To use a different map SDK, depend on the interface package and register your own provider at the same point during startup.

## Compatibility

### Map compatibility

**Compatibility Table**

**Query:** `elements.map`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/elements/map.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| map | Yes (4.5) | Yes (4.5) | Yes (4.5) | Unknown | Unknown | No |
| attributes | Yes (4.5) | Yes (4.5) | Yes (4.5) | Unknown | Unknown | Unknown |
| attributes.center | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.scale | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.enable-scale | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.enable-drag | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.enable-rotate | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.enable-tilt | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| events | Yes (4.5) | Yes (4.5) | Yes (4.5) | Unknown | Unknown | Unknown |
| events.bindmapload | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| methods | Yes (4.5) | Yes (4.5) | Yes (4.5) | Unknown | Unknown | Unknown |
| methods.setCenter | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| methods.getCenter | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| methods.setScale | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| methods.getScale | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |

**`map`**

map

**Status:** Experimental

**`attributes`**

attributes

**`attributes.center`**

<code>center</code>

**`attributes.scale`**

<code>scale</code>

**`attributes.enable-scale`**

<code>enable-scale</code>

**`attributes.enable-drag`**

<code>enable-drag</code>

**`attributes.enable-rotate`**

<code>enable-rotate</code>

**`attributes.enable-tilt`**

<code>enable-tilt</code>

**`events`**

events

**`events.bindmapload`**

<code>bindmapload</code>

**`methods`**

methods

**`methods.setCenter`**

<code>setCenter</code>

**`methods.getCenter`**

<code>getCenter</code>

**`methods.setScale`**

<code>setScale</code>

**`methods.getScale`**

<code>getScale</code>


### Marker compatibility

**Compatibility Table**

**Query:** `elements.map-marker`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/elements/map-marker.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| map-marker | Yes (4.5) | Yes (4.5) | Yes (4.5) | Unknown | Unknown | No |
| attributes | Yes (4.5) | Yes (4.5) | Yes (4.5) | Unknown | Unknown | Unknown |
| attributes.position | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.anchor | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.z-index | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.alpha | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| attributes.enable-click | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| events | Yes (4.5) | Yes (4.5) | Yes (4.5) | Unknown | Unknown | Unknown |
| events.bindclickmarker | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |
| methods | Yes (4.5) | Yes (4.5) | Yes (4.5) | Unknown | Unknown | Unknown |
| methods.refreshMarker | Yes (4.5) | Yes (4.5) | Yes (4.5) | No | No | No |

**`map-marker`**

map-marker

**Status:** Experimental

**`attributes`**

attributes

**`attributes.position`**

<code>position</code>

**`attributes.anchor`**

<code>anchor</code>

**`attributes.z-index`**

<code>z-index</code>

**`attributes.alpha`**

<code>alpha</code>

**`attributes.enable-click`**

<code>enable-click</code>

**`events`**

events

**`events.bindclickmarker`**

<code>bindclickmarker</code>

**`methods`**

methods

**`methods.refreshMarker`**

<code>refreshMarker</code>

