문서 / 설정 / iOS / Apple MapKit
Apple MapKit 설정
Apple의 MapKit을 MapConductor에서 쓰는 절차입니다. 외부 의존도 API 키도 SDK의 초기화도 불필요하며, iOS의 프로바이더로서는 가장 준비가 적게 듭니다.
PACKAGE
ios-for-mapkit
API KEY
불필요
MIN iOS
15.1
VIEW
MapKitMapView
같은 프로바이더, 다른 플랫폼React
시작하기 전에
Xcode 15 이상
디플로이 타깃 iOS 15.1 이상
STEP 01
Swift Package Manager로 추가한다
MapKit은 iOS에 동봉되어 있기 때문에, 추가 계정이나 키, 초기화는 필요 없습니다. 패키지를 추가하기만 하면 됩니다.
Package URLSwift Package Manager
https://github.com/MapConductor/ios-for-mapkit
Package.swiftSwift
dependencies: [
.package(url: "https://github.com/MapConductor/ios-sdk-core", from: "1.3.1"),
.package(url: "https://github.com/MapConductor/ios-for-mapkit", from: "1.0.0"),
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "MapConductorCore", package: "ios-sdk-core"),
.product(name: "MapConductorForMapKit", package: "ios-for-mapkit"),
]
),
]STEP 02
위치 정보의 권한을 더한다(필요한 경우)
위치 정보를 쓰는 경우는 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()
}
}동작 확인
여기까지 보이면 완료
지도가 나오고 줌과 팬이 들으면 완료입니다.
ContentView.swiftSwiftUI
import SwiftUI
import MapConductorCore
import MapConductorForMapKit
struct ContentView: View {
@StateObject var mapState = MapKitViewState(
mapDesignType: MapKitMapDesign.Standard,
cameraPosition: MapCameraPosition(
position: GeoPoint(latitude: 35.6812, longitude: 139.7671),
zoom: 12.0
)
)
var body: some View {
MapKitMapView(state: mapState)
.ignoresSafeArea()
}
}지도 디자인
MapKitMapDesign은 MKMapType에 대응합니다.
MapKitMapDesign
Notes
Standard
표준의 도로 지도
Satellite
위성 화상
Hybrid
위성 화상+도로와 라벨
MutedStandard
데이터를 얹는 바탕용의 옅은 스타일
잘 안 될 때
지도가 나오지 않는다
- 디플로이 타깃이 iOS 15.1 이상인지 확인합니다.
- MapConductorForMapKit이 타깃에 링크되어 있는지 확인합니다.
빌드가 통과하지 않는다
- 빌드 폴더를 지웁니다(Cmd+Shift+K).
- ~/Library/Developer/Xcode/DerivedData를 삭제하고 다시 빌드합니다.
- Swift Package Manager의 의존을 갱신합니다. CocoaPods와의 병용은 피해 주세요.
다음
Apple 플랫폼만을 대상으로 한다면, 추가 SDK도 키도 불필요한 만큼 배포 크기도 작아집니다. Web에서도 MapKit JS 판의 프로바이더를 쓸 수 있습니다.