Skip to content

MapView API ​

MapView is the core component for map rendering, user location display, camera control, event callbacks, and snapshots.

⚠️ Privacy requirement

Before rendering MapView or calling any map / location capability, a fresh install must complete privacy compliance first. Once granted, privacy state is persisted natively and auto-restored on later cold starts.

If privacy is not ready, the JS layer throws a clear error before the native SDK can fail.

Props ​

Basic configuration ​

PropertyTypeDefaultDescription
mapTypeMapTypeMapType.StandardMap type
initialCameraPositionCameraPosition-Initial camera position
styleStyleProp<ViewStyle>-Map style; usually requires flex: 1
worldMapSwitchEnabledbooleanfalseAutomatically switch between domestic and world map, iOS only
customMapStyle{ styleId?: string; styleDataPath?: string; extraStyleDataPath?: string }-Custom map style
PropertyTypeDefaultDescription
myLocationEnabledbooleanfalseShow user location
followUserLocationbooleanfalseFollow user location
userLocationRepresentationUserLocationRepresentation-Blue-dot appearance configuration
distanceFilternumber-Minimum location update distance in meters, iOS only
headingFilternumber-Minimum heading change in degrees, iOS only

UserLocationRepresentation ​

Shared properties

PropertyTypeDefaultDescription
showMyLocationbooleantrueWhether to show the location dot
showsAccuracyRingbooleantrueWhether to show the accuracy ring
fillColorstring | number-Accuracy ring fill color
strokeColorstring | number-Accuracy ring stroke color
lineWidthnumber0Accuracy ring stroke width
imagestring-Custom location icon
imageWidthnumber-Icon width
imageHeightnumber-Icon height

iOS only

PropertyTypeDefaultDescription
showsHeadingIndicatorbooleantrueShow heading cone
enablePulseAnimationbooleantrueEnable pulse animation
locationDotBgColorstring | number'white'Location dot background color
locationDotFillColorstring | number'blue'Location dot fill color

Android only

PropertyTypeDefaultDescription
anchorUnumber-Icon anchor U
anchorVnumber-Icon anchor V
locationType'SHOW' | 'LOCATE' | 'FOLLOW' | 'MAP_ROTATE' | 'LOCATION_ROTATE' | 'LOCATION_ROTATE_NO_CENTER' | 'FOLLOW_NO_CENTER' | 'MAP_ROTATE_NO_CENTER''LOCATION_ROTATE_NO_CENTER'Blue-dot display mode

Android locationType ​

  • 'SHOW': locate once
  • 'LOCATE': locate once and move camera to center
  • 'FOLLOW': continuous updates, follows user, icon does not rotate
  • 'MAP_ROTATE': rotate the map based on device heading
  • 'LOCATION_ROTATE': rotate the location icon and keep it centered
  • 'LOCATION_ROTATE_NO_CENTER': rotate the location icon without re-centering
  • 'FOLLOW_NO_CENTER': continuous updates without re-centering
  • 'MAP_ROTATE_NO_CENTER': rotate the map without re-centering

When locationType is set explicitly, it overrides the default mode selected by followUserLocation.

Map display and controls ​

PropertyTypeDefaultDescription
indoorViewEnabledbooleanfalseShow indoor map
buildingsEnabledbooleantrueShow 3D buildings
labelsEnabledbooleantrueShow map labels
compassEnabledbooleantrueShow compass
zoomControlsEnabledbooleantrueShow zoom controls, Android only
scaleControlsEnabledbooleantrueShow scale bar
myLocationButtonEnabledbooleanfalseShow my-location button, Android only
trafficEnabledbooleanfalseShow traffic layer

Gestures and zoom ​

PropertyTypeDefaultDescription
maxZoomnumber20Maximum zoom level
minZoomnumber3Minimum zoom level
zoomGesturesEnabledbooleantrueEnable pinch zoom
zoomGestureAnchor'gesture' | 'center''gesture'Pinch zoom anchor. gesture follows the gesture focal point, center keeps the map center fixed
scrollGesturesEnabledbooleantrueEnable pan gestures
rotateGesturesEnabledbooleantrueEnable rotate gestures
tiltGesturesEnabledbooleantrueEnable tilt gestures

Events ​

EventParametersDescription
onMapPressNativeSyntheticEvent<LatLng>Tap empty map area
onPressPoiNativeSyntheticEvent<MapPoi>Tap a POI
onMapLongPressNativeSyntheticEvent<LatLng>Long press on map
onCameraMoveNativeSyntheticEvent<CameraEvent>Fires continuously while camera moves
onCameraIdleNativeSyntheticEvent<CameraEvent>Fires after camera movement ends
onLoadNativeSyntheticEvent<{}>Map finished loading
onLocationNativeSyntheticEvent<LocationEvent>Blue-dot location update

Camera event throttling ​

  • Use cameraEventThrottleMs?: number to control the native onCameraMove event frequency in milliseconds
  • Default is 32; pass 0 to disable throttling and receive all move events in JS

MapViewRef ​

Use a ref to call:

tsx
interface MapViewRef {
  moveCamera(position: CameraUpdate, duration?: number): Promise<void>;
  getLatLng(point: Point): Promise<LatLng>;
  setCenter(center: LatLngPoint, animated?: boolean): Promise<void>;
  setZoom(zoom: number, animated?: boolean): Promise<void>;
  getCameraPosition(): Promise<CameraPosition>;
  takeSnapshot(): Promise<string>;
}
MethodParametersReturnDescription
moveCamera(position, duration?)Promise<void>Move the camera
getLatLng(point)Promise<LatLng>Convert screen point to geo coordinate
setCenter(center, animated?)Promise<void>Set map center
setZoom(zoom, animated?)Promise<void>Set zoom level
getCameraPosition-Promise<CameraPosition>Get current camera state
takeSnapshot-Promise<string>Capture a snapshot and return the image file path

Usage examples ​

Basic map ​

tsx
import { ExpoGaodeMapModule, MapType, MapView } from 'expo-gaode-map';

if (!ExpoGaodeMapModule.getPrivacyStatus().isReady) {
  ExpoGaodeMapModule.setPrivacyConfig({
    hasShow: true,
    hasContainsPrivacy: true,
    hasAgree: true,
  });
}

export default function App() {
  return (
    <MapView
      style={{ flex: 1 }}
      mapType={MapType.Standard}
      initialCameraPosition={{
        target: { latitude: 39.9, longitude: 116.4 },
        zoom: 10,
      }}
      onLoad={() => console.log('Map loaded')}
    />
  );
}

Control camera with ref ​

tsx
import { useRef } from 'react';
import { Button, View } from 'react-native';
import { MapView, type MapViewRef } from 'expo-gaode-map';

export default function CameraExample() {
  const mapRef = useRef<MapViewRef | null>(null);

  const handleMoveCamera = async () => {
    await mapRef.current?.moveCamera(
      {
        target: { latitude: 40.0, longitude: 116.5 },
        zoom: 15,
        tilt: 30,
      },
      1000
    );
  };

  return (
    <View style={{ flex: 1 }}>
      <MapView
        ref={mapRef}
        style={{ flex: 1 }}
        initialCameraPosition={{
          target: { latitude: 39.9, longitude: 116.4 },
          zoom: 10,
        }}
      />
      <Button title="Move Camera" onPress={handleMoveCamera} />
    </View>
  );
}

Listen to POI / camera / location ​

tsx
<MapView
  style={{ flex: 1 }}
  myLocationEnabled
  onPressPoi={(e) => console.log('POI', e.nativeEvent)}
  onCameraMove={(e) => console.log('Moving', e.nativeEvent.cameraPosition)}
  onCameraIdle={(e) => console.log('Idle', e.nativeEvent.latLngBounds)}
  onLocation={(e) => console.log('Blue dot', e.nativeEvent)}
/>

Snapshot ​

takeSnapshot() returns an image file path. If you render floating UI inside MapUI, those UI elements are also included in the snapshot.

tsx
const uri = await mapRef.current?.takeSnapshot();
console.log('Snapshot path:', uri);

Extra types ​

CameraPosition ​

ts
interface CameraPosition {
  target?: LatLng;
  zoom?: number;
  tilt?: number;
  bearing?: number;
}

LocationEvent ​

ts
interface LocationEvent {
  latitude: number;
  longitude: number;
  accuracy: number;
}

CameraEvent ​

ts
interface CameraEvent {
  cameraPosition: CameraPosition;
  latLngBounds: LatLngBounds;
}