SwiftUI에 GoogleMap 표시
                                            
                                                
                                                
                                                
                                                
                                                
                                                 3871 단어  iOSSwiftUIGoogle Maptech
                    
프로젝트의 설정을 잊어버리기 쉽기 때문에, 비망록의 첫 번째 투고도 겸한다💁🏻
사전 준비
이후 API 키 등 다양한 준비가 완료되는 전제로 진행된다.
프로젝트 준비
새 프로젝트를 작성한 후 다음을 참조하여 Maps SDK for iOS를 추가합니다.
Project에 API 키 추가
SwiftUI에서 프로젝트를 새로 만든 후
AppDelegate가 없습니다. 아래 설명을 추가하십시오.import Foundation
import GoogleMaps
class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        GMSServices.provideAPIKey("YOUR_API_KEY")
        return true
    }
}
 Place API 등 기타 API를 사용하는 경우GMSPlacesClient.provideAPIKey("YOUR_API_KEY")
 등 똑같이 추가하면 됩니다.이를 적용하기 위해 추가된
AppDelegate.swift 편집プロジェクト名App.swiftimport SwiftUI
@main
struct GoogleMapDemoApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    ...
}
  맵 표시
Step4: Add a map의 코드는 ViewController의 것으로 추가되어도 움직이지 않습니다.
SwiftUI에서 사용
UIViewRepresentable Map 표시GoogleMap을 표시하기 위한 뷰는 다음과 같습니다.
import SwiftUI
import GoogleMaps
struct MapView: UIViewRepresentable {
    let mapView = GMSMapView(frame: .zero)
    
    func makeUIView(context: Context) -> GMSMapView {
        return mapView
    }
    func updateUIView(_ mapView: GMSMapView, context: Context) {
    }
}
ContentView.swift에 이걸 추가하면...struct ContentView: View {
    var body: some View {
        MapView()
    }
}
  
 표시됨!
맞아요.
struct ContentView: View {
    var body: some View {
        MapView().ignoresSafeArea()
    }
}
MapView더하면.ignoreSafeArea()지도가 다 나와요.
 끝맺다
성과물은 여기 있습니다.
다음에는 지도에 현재 소재지를 표시하고 싶어요.
참고 자료
https://developers.google.com/maps/documentation/ios-sdk/overview
https://developers.google.com/maps/documentation/ios-sdk/config
https://developers.google.com/maps/documentation/ios-sdk/config#add-map
https://kumano-te.com/activities/google-maps-sdk-swiftui
Reference
이 문제에 관하여(SwiftUI에 GoogleMap 표시), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/mimimimi/articles/ae0b0988961fde텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)