iOS 配置
复制一条配置 prompt,包含安装步骤和该插件的完整 Markdown 指南。
iOS 使用 Apple MapKit。你可以 不 在 iOS 上需要 Google Maps API key。
如果您调用 enableCurrentLocation,请向 ... 添加位置使用说明字符串 ios/App/App/Info.plist:
<key>NSLocationWhenInUseUsageDescription</key><string>We use your location to show you on the map.</string>该插件通过 ... 请求位置权限 keepAlive 以便 enableCurrentLocation 在获得权限后可以可靠地解析。
WebView 后方的地图
标题为 “Map behind the WebView” 的章节原生 MKMapView 挂载到 Capacitor WKWebView 层级中,并通过 ... 追踪绑定的 DOM 元素 onResize 和 onDisplay. 当 Ionic 页面重新进入时,如果 WebKit 重建了 scroll views,插件中的调用路径会重新挂载地图。
在地图容器上方的 HTML 层中使用透明的 WebView 或页面背景,以便地图能够透显出来。
在 toBack 模式,放置 data-map-overlay 在 HUD 包装器上,以便 README 的 overlay CSS 能够启用点击。当命中目标是透明且不在交互元素下方时,原生 touch router 会将手势发送给地图。
仅限 iOS 的插件方法
标题为“仅限 iOS 的插件方法”的部分原生 iOS bridge 还会暴露 takeSnapshot, searchAutocomplete, searchPlaces, searchResolve, geocode,以及 reverseGeocode. 这些方法尚未包含在 NativeMap class wrapper 中。当您需要在 iOS 上使用 MapKit 搜索或地理编码时,请在低层级 plugin handle 上调用它们:
import { registerPlugin } from '@capacitor/core';
type NativeMapBridge = { takeSnapshot(options: { id: string }): Promise<{ image: string }>; geocode(options: { address: string }): Promise<Record<string, unknown>>;};
const NativeMapBridge = registerPlugin<NativeMapBridge>('NativeMap');