ArcGIS का सेटअप
MapConductor से ArcGIS Maps SDK for Swift का उपयोग करने के चरण। ArcGIS के बेसमैप को ArcGISDesign में चुना जा सकता है, और 3D और 2D दोनों व्यू उपयोग किए जा सकते हैं।
शुरू करने से पहले
API कुंजी प्राप्त करें
- ArcGIS Location Platform या ArcGIS Developers पर जाएं।
- प्रोजेक्ट के लिए API कुंजी बनाएं।
- आवश्यक ArcGIS सेवाओं (बेसमैप, जियोकोडिंग, रूटिंग आदि) को सक्षम करें।
- ऐप के उपयोग के अनुसार कुंजी को प्रतिबंधित करें।
Swift Package Manager के साथ जोड़ें
Xcode के File > Add Package Dependencies से पैकेज URL दर्ज करें। ArcGIS Maps SDK for Swift स्वचालित रूप से निर्भरता के रूप में जुड़ जाएगा।
https://github.com/MapConductor/ios-for-arcgis
dependencies: [
.package(url: "https://github.com/MapConductor/ios-sdk-core", from: "1.3.1"),
.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"),
]
),
]SDK को इनिशियलाइज़ करें
मैप व्यू बनने से पहले arcGISApiKeyInitialize(apiKey:) को केवल एक बार कॉल करें।
import SwiftUI
import MapConductorForArcGIS
@main
struct MyApp: App {
init() {
_ = arcGISApiKeyInitialize(apiKey: "YOUR_ARCGIS_API_KEY")
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}// Alternative: call it from the view's sdkInitialize closure
ArcGISMapView(state: mapState, sdkInitialize: {
_ = arcGISApiKeyInitialize(apiKey: "YOUR_ARCGIS_API_KEY")
})स्थान अनुमति जोड़ें (यदि आवश्यक हो)
यदि आप स्थान का उपयोग करते हैं तो Info.plist में उद्देश्य लिखें।
<key>NSLocationWhenInUseUsageDescription</key> <string>We need your location to display on the map</string>
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 होने पर) टिल्ट काम करना सुनिश्चित करें।
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:) के माध्यम से बनाया जा सकता है।
समस्या निवारण
मानचित्र पूरी तरह सफेद है
- जांचें कि arcGISApiKeyInitialize(apiKey:) मैप व्यू से पहले कॉल किया गया है या नहीं।
- जांचें कि कुंजी द्वारा आवश्यक ArcGIS सेवाएं सक्षम हैं या नहीं।
- जांचें कि डिप्लॉय टारगेट iOS 17.0 या इससे ऊपर है या नहीं।
बिल्ड विफल हो रहा है
- बिल्ड फ़ोल्डर को क्लियर करें (Cmd+Shift+K)।
- ~/Library/Developer/Xcode/DerivedData को हटाएं और पुनः बिल्ड करें।
- Swift Package Manager निर्भरता को अपडेट करें। CocoaPods के साथ उपयोग से बचें।
आगे
ArcGISMapView 3D है और ArcGISMapView2D 2D है। दोनों एक ही स्टेट ऑब्जेक्ट साझा करते हैं।