跳转到正文

iOS 配置

GitHub
iOS 模拟器录制,使用 Apple MapKit:门店定位图钉、配送区域、路线、500 个聚合标记、倾斜的 3D 相机以及卫星地图类型

iOS 使用 Apple MapKit。您无需 不会 在 iOS 上配置 Google Maps API 密钥。

如果您调用 enableCurrentLocation,请在 中添加位置用途字符串 ios/App/App/Info.plist:

<key>NSLocationWhenInUseUsageDescription</key>
<string>We use your location to show you on the map.</string>

该插件请求位置权限时 keepAlive 以便 enableCurrentLocation 在权限授予后,可以可靠地解析。

原生 MKMapView 挂载到 Capacitor WKWebView 层级中,并通过 onResize 以及 onDisplay跟踪绑定的 DOM 元素。当 Ionic 页面重新进入时,如果 WebKit 重建了滚动视图,插件中的调用路径会重新挂载地图。

在地图应透过 HTML 层显示在地图容器上方的地方,使用透明的 WebView 或页面背景。

在 toBack 模式下,将 data-map-overlay 放在 HUD 包装器上,以便 README 覆盖层 CSS 启用点击。当命中目标是透明的且不在交互元素下方时,原生触摸路由器会将手势发送给地图。

iOS 原生桥接层还暴露了 takeSnapshot, searchAutocomplete, searchPlaces, searchResolve, geocode,以及 reverseGeocode。这些还不在 NativeMap 类封装上。当需要在 iOS 上用 MapKit 搜索或地理编码时,请通过底层插件句柄调用:

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');