Skip to content

MapView API

MapView is the core component for displaying maps.

Props

Basic Configuration

PropertyTypeDefaultDescription
mapTypeMapType0Map type (0: Standard, 1: Satellite, 2: Night, 3: Navi, 4: Bus)
worldMapSwitchEnabledbooleanfalseWhether to enable automatic switching between domestic and foreign maps (iOS)
initialCameraPositionCameraPosition-Initial camera position
styleViewStyle-Component style
PropertyTypeDefaultDescription
myLocationEnabledbooleanfalseWhether to show location dot
followUserLocationbooleanfalseWhether to follow user location

Control Display

PropertyTypeDefaultDescription
zoomControlsEnabledbooleantrueWhether to show zoom controls (Android)
compassEnabledbooleantrueWhether to show compass
scaleControlsEnabledbooleantrueWhether to show scale controls

Gesture Control

PropertyTypeDefaultDescription
zoomGesturesEnabledbooleantrueEnable zoom gestures
scrollGesturesEnabledbooleantrueEnable scroll gestures
rotateGesturesEnabledbooleantrueEnable rotate gestures
tiltGesturesEnabledbooleantrueEnable tilt gestures

Zoom Control

PropertyTypeDefaultDescription
maxZoomnumber20Maximum zoom level (3-20)
minZoomnumber3Minimum zoom level (3-20)

Layer Display

PropertyTypeDefaultDescription
trafficEnabledbooleanfalseWhether to show traffic
buildingsEnabledbooleantrueWhether to show 3D buildings
indoorViewEnabledbooleanfalseWhether to show indoor map

Event Callbacks

EventParametersDescription
onMapPress(event: NativeSyntheticEvent<LatLng>) => voidMap press event
onMapLongPress(event: NativeSyntheticEvent<LatLng>) => voidMap long press event
onLoad(event: NativeSyntheticEvent<{}>) => voidMap load complete event

MapView Methods

Called via Ref:

tsx
interface MapViewRef {
  // Camera control
  moveCamera(position: CameraPosition, duration?: number): Promise<void>;
  setCenter(center: LatLng, animated?: boolean): Promise<void>;
  setZoom(zoom: number, animated?: boolean): Promise<void>;
  getCameraPosition(): Promise<CameraPosition>;
  getLatLng(point: Point): Promise<LatLng>;
  /**
   * Take a snapshot of the map
   * @returns Path to the snapshot image file
   */
  takeSnapshot(): Promise<string>;
}

Components and Hooks

useMap

tsx
import { useMap } from "expo-gaode-map";

function ZoomInButton() {
  const map = useMap();
  return (
    <Button
      title="Zoom In"
      onPress={async () => {
        const current = await map.getCameraPosition();
        await map.setZoom((current.zoom ?? 10) + 1, true);
      }}
    />
  );
}

MapUI

tsx
import { MapUI, MapView } from "expo-gaode-map";

<MapView style={{ flex: 1 }}>
  <MapUI>
    <Text>Overlay UI</Text>
  </MapUI>
</MapView>;

Usage Examples

Basic Usage

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

<MapView
  style={{ flex: 1 }}
  initialCameraPosition={{
    target: { latitude: 39.9, longitude: 116.4 },
    zoom: 10,
  }}
  myLocationEnabled={true}
  onLoad={() => console.log('Map loaded')}
/>

Using Ref to Control Camera

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

const mapRef = useRef<MapViewRef>(null);

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

<MapView
  ref={mapRef}
  style={{ flex: 1 }}
  initialCameraPosition={{
    target: { latitude: 39.9, longitude: 116.4 },
    zoom: 10,
  }}
/>

Type Definitions

CameraPosition

typescript
interface CameraPosition {
  target: LatLng;    // Target location
  zoom: number;      // Zoom level (3-20)
  tilt?: number;     // Tilt angle (0-60)
  bearing?: number;  // Rotation angle (0-360)
}

LatLng

typescript
interface LatLng {
  latitude: number;   // Latitude
  longitude: number;  // Longitude
}