Guide
How to use Native Map in Capacitor
Using @capgo/capacitor-native-map
Google Maps on Android, Apple MapKit on iOS, and Google Maps JS on web with one TypeScript API for markers, camera, shapes, clustering, and events.
Install
bun add @capgo/capacitor-native-map
bunx cap sync
What This Plugin Exposes
create: embedded map in a DOM element, ortoBack: truefor a map behind transparent HTML.updateLayout: resize and reposition the native map (CSS pixels).setCamera/fitBounds: camera and viewport control.addMarker/addMarkers/removeMarker: markers with tap and drag listeners.enableClustering: group dense marker sets.enableCurrentLocation: user location dot when permission allows.- Overlays: polygons, polylines, circles, and tile layers (varies by platform).
Example Usage
Embedded map
import { NativeMap } from '@capgo/capacitor-native-map';
const map = await NativeMap.create({
id: 'main-map',
element: document.getElementById('map')!,
apiKey: 'YOUR_GOOGLE_MAPS_API_KEY',
config: {
center: { lat: 37.7749, lng: -122.4194 },
zoom: 12,
},
});
map.setOnMapClickListener((e) => console.log(e.latitude, e.longitude));
// In a framework component, call `await map.destroy()` from your teardown/cleanup hook.
Background map with HTML UI
const map = await NativeMap.create({
id: 'stores-map',
toBack: true,
apiKey: 'YOUR_GOOGLE_MAPS_API_KEY',
config: {
center: { lat: 40.7128, lng: -74.006 },
zoom: 11,
x: 0,
y: 0,
width: window.innerWidth,
height: window.innerHeight,
},
});
await map.updateLayout({
x: 0,
y: 0,
width: window.innerWidth,
height: window.innerHeight,
});
Wrap HUD sections with data-map-overlay (see getting started) so the overlay CSS enables taps; transparent areas pass gestures to the map.
Full Reference
- GitHub: https://github.com/Cap-go/capacitor-native-map/
- Docs: /docs/plugins/native-map/