ドキュメント / セットアップ / iOS / ArcGIS

ArcGIS セットアップ

ArcGIS Maps SDK for Swift を MapConductor から使う手順です。ArcGIS のベースマップを ArcGISDesign で選べ、3D と 2D の両方のビューが使えます。

PACKAGE
ios-for-arcgis
API KEY
必要
MIN iOS
17.0
VIEW
ArcGISMapView / 2D
ほかのプラットフォームAndroidReact

前提

Xcode 15 以上
ArcGIS 開発者アカウント
ArcGIS の API キー
デプロイターゲット iOS 17.0 以上
STEP 01

API キーを取得する

  1. ArcGIS Location Platform または ArcGIS Developers にアクセスします。
  2. プロジェクト用の API キーを作成します。
  3. 必要な ArcGIS サービス(ベースマップ、ジオコーディング、ルーティングなど)を有効にします。
  4. キーをアプリの用途に合わせて制限します。
STEP 02

Swift Package Manager で追加する

Xcode の File > Add Package Dependencies からパッケージ URL を入力します。ArcGIS Maps SDK for Swift は依存関係として自動的に入ります。

Package URLSwift Package Manager
https://github.com/MapConductor/ios-for-arcgis
Package.swiftSwift
dependencies: [
    .package(url: "https://github.com/MapConductor/ios-sdk-core", from: "1.1.4"),
    .package(url: "https://github.com/MapConductor/ios-for-arcgis", from: "1.0.0"),
],
targets: [
    .target(
        name: "YourApp",
        dependencies: [
            .product(name: "MapConductorCore", package: "ios-sdk-core"),
            .product(name: "MapConductorForArcGIS", package: "ios-for-arcgis"),
        ]
    ),
]
STEP 03

SDK を初期化する

地図ビューが作られる前に arcGISApiKeyInitialize(apiKey:) を一度だけ呼びます。

MyApp.swiftSwift
import SwiftUI
import MapConductorForArcGIS

@main
struct MyApp: App {
    init() {
        _ = arcGISApiKeyInitialize(apiKey: "YOUR_ARCGIS_API_KEY")
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
ContentView.swiftSwift
// Alternative: call it from the view's sdkInitialize closure
ArcGISMapView(state: mapState, sdkInitialize: {
    _ = arcGISApiKeyInitialize(apiKey: "YOUR_ARCGIS_API_KEY")
})
STEP 04

位置情報の権限を足す(必要な場合)

位置情報を使う場合は Info.plist に用途を書きます。

Info.plistXML
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location to display on the map</string>
LocationManager.swiftSwift
import CoreLocation

final class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
    private let manager = CLLocationManager()

    override init() {
        super.init()
        manager.delegate = self
    }

    func requestPermission() {
        manager.requestWhenInUseAuthorization()
    }
}

動作確認

ここまで動けば完了

3D ビューで地図を出します。同じ状態オブジェクトを ArcGISMapView2D に渡せば 2D 表示になります。ズーム・パン・(3D なら)チルトが効けば完了です。

ContentView.swiftSwiftUI
import SwiftUI
import MapConductorCore
import MapConductorForArcGIS

struct ContentView: View {
    @StateObject var mapState = ArcGISMapViewState(
        mapDesignType: ArcGISDesign.Streets,
        cameraPosition: MapCameraPosition(
            position: GeoPoint(latitude: 35.6812, longitude: 139.7671),
            zoom: 12.0
        )
    )

    var body: some View {
        // 3D scene view; ArcGISMapView2D takes the very same state
        ArcGISMapView(state: mapState)
            .ignoresSafeArea()
    }
}

地図デザイン

ArcGISDesign は Esri のベースマップに対応します。既知の ID からは ArcGISDesign.Create(id:) で作れます。

ArcGISDesign
Notes
Streets
標準の道路地図
Imagery
衛星画像
Topographic
地形図
OsmStandard
OpenStreetMap 標準スタイル
NavigationNight
夜間ナビゲーション
DarkGray
データを載せる下地向け

うまくいかないとき

地図が真っ白のまま

  • arcGISApiKeyInitialize(apiKey:) が地図ビューより先に呼ばれているか確認します。
  • キーで必要な ArcGIS サービスが有効か確認します。
  • デプロイターゲットが iOS 17.0 以上か確認します。

ビルドが通らない

  • ビルドフォルダーをクリアします(Cmd+Shift+K)。
  • ~/Library/Developer/Xcode/DerivedData を削除して再ビルドします。
  • Swift Package Manager の依存を更新します。CocoaPods との併用は避けてください。

次に

ArcGISMapView は 3D、ArcGISMapView2D は 2D です。両者は同じ状態オブジェクトを共有します。