결제를 사용 설정하고 API 키를 만든 후에는 앱 개발에 사용할 Xcode 프로젝트를 설정할 수 있습니다.
각 출시 버전에서 출시 노트를 확인할 수 있습니다.
1단계: 필수 소프트웨어 설치하기
iOS용 Maps SDK를 사용하여 프로젝트를 빌드하려면 다음을 다운로드하여 설치해야 합니다.
2단계: Xcode 프로젝트 만들기 및 iOS용 Maps SDK 설치하기
새 프로젝트에 API를 설치하려면 다음 단계를 따르세요.
CocoaPods 사용
iOS용 Maps SDK는 CocoaPods pod로 제공됩니다. CocoaPods는 Swift 및 Objective-C Cocoa 프로젝트용 오픈소스 종속 항목 관리자입니다.
아직 CocoaPods 도구가 없으면 터미널에서 다음 명령어를 실행하여 macOS에 CocoaPods 도구를 설치합니다. 자세한 내용은 CocoaPods 시작 가이드를 참고하세요.
sudo gem install cocoapods
iOS용 Maps SDK를 위한 Podfile
을 만들고 이를 사용하여 API와 종속 항목을 설치합니다.
- 아직 Xcode 프로젝트가 없으면 지금 만들어 로컬 머신에 저장합니다. iOS를 처음 개발하는 경우:
- 새 프로젝트를 만듭니다.
- iOS > App 템플릿을 선택합니다.
- 프로젝트 옵션 화면에서 다음 단계를 따릅니다.
- Project Name(프로젝트 이름)을 입력합니다.
- 번들 식별자 필드의 값을 기록합니다. 이 값을 사용하여 아래의 API 키를 제한할 수 있습니다.
- 프로젝트 Interface를 Storyboard로 설정합니다.
- Language를 Swift 또는 Objective-C로 설정합니다.
- 프로젝트 디렉터리에
Podfile
파일을 만듭니다. 이 파일은 프로젝트의 종속 항목을 정의합니다. Podfile
를 수정하고 versions과 함께 종속 항목을 추가합니다. 다음은 iOS용 Maps SDK에 필요한 종속 항목이 포함된 예입니다.source 'https://github.com/CocoaPods/Specs.git' platform :ios, '14.0' target 'YOUR_APPLICATION_TARGET_NAME_HERE' do pod 'GoogleMaps', '8.3.0' end
항상 최신 버전을 사용하려면 정기적으로pod outdated
를 실행하여 최신 버전이 있는지 확인해야 합니다. 필요한 경우 최신 버전으로 업그레이드하세요.Podfile
을 저장합니다.터미널을 열고
Podfile
가 포함된 디렉터리로 이동합니다.cd <path-to-project>
pod install
명령어를 실행합니다.Podfile
에 지정된 API가 API에 포함된 종속 항목과 함께 설치됩니다.pod install
Xcode를 닫은 다음 프로젝트의
.xcworkspace
파일을 (더블클릭하여) 열어 Xcode를 실행합니다. 이 때부터는.xcworkspace
파일을 사용하여 프로젝트를 열어야 합니다.
기존 프로젝트의 API를 업데이트하려면 다음 단계를 따르세요.
- 터미널을 열고
Podfile
가 포함된 프로젝트 디렉터리로 이동합니다. pod update
명령어를 실행합니다. 이렇게 하면Podfile
에 지정된 모든 API가 최신 버전으로 업데이트됩니다.
수동 설치
이 가이드에서는 iOS용 Maps SDK가 포함된 XCFrameworks를 프로젝트에 수동으로 추가하고 Xcode에서 빌드 설정을 구성하는 방법을 설명합니다. XCFramework는 Apple silicon을 사용하는 머신을 비롯한 여러 플랫폼에서 사용할 수 있는 바이너리 패키지입니다.- 다음 SDK 바이너리 및 리소스 파일을 다운로드합니다.
- 압축된 파일의 압축을 풀어 XCFrameworks 및 리소스에 액세스하세요.
- 아직 Xcode 프로젝트가 없으면 지금 만들어 로컬 머신에 저장합니다. iOS를 처음 개발하는 경우:
- 새 프로젝트를 만듭니다.
- iOS > App 템플릿을 선택합니다.
- 프로젝트 옵션 화면에서 다음 단계를 따릅니다.
- Project Name(프로젝트 이름)을 입력합니다.
- 번들 식별자 필드의 값을 기록합니다. 이 값을 사용하여 아래의 API 키를 제한할 수 있습니다.
- 프로젝트 Interface를 Storyboard로 설정합니다.
- Language를 Swift 또는 Objective-C로 설정합니다.
- 다음 XCFrameworks를 프레임워크, 라이브러리 및 삽입된 콘텐츠의 프로젝트로 드래그합니다. 각 XCFramework에 대해 Do Not Embed(삽입 안함)를 선택해야 합니다.
GoogleMaps.xcframework
GoogleMapsBase.xcframework
GoogleMapsCore.xcframework
- (프리미엄 플랜 고객만 해당)
GoogleMapsM4B.xcframework
- 다운로드한 GoogleMapsResources에서
Xcode 프로젝트의 최상위 디렉터리로
GoogleMaps.bundle
를 드래그합니다. 메시지가 표시되면 Copy items if needed(필요한 경우 항목 복사)가 선택되어 있는지 확인합니다. - 프로젝트 탐색기에서 프로젝트를 선택하고 애플리케이션의 대상을 선택합니다.
- 바이너리를 라이브러리와 연결 내에서 애플리케이션 타겟의 빌드 단계 탭을 열고 다음 프레임워크와 라이브러리를 추가합니다.
Accelerate.framework
CoreData.framework
CoreGraphics.framework
CoreImage.framework
CoreLocation.framework
CoreTelephony.framework
CoreText.framework
GLKit.framework
ImageIO.framework
libc++.tbd
libz.tbd
Metal.framework
OpenGLES.framework
QuartzCore.framework
SystemConfiguration.framework
UIKit.framework
특정 대상 대신 자신의 프로젝트를 선택하고 Build Settings(빌드 설정) 탭을 엽니다. Other Linker Flags(기타 링커 플래그) 섹션에서
-ObjC
를 추가합니다. 이러한 설정이 표시되지 않으면 Build Settings(빌드 설정) 표시줄의 필터를 Basic(기본)에서 All(모두)로 변경합니다.iOS XCFramework용 Places SDK를 설치하려면 iOS용 Places SDK 시작하기를 참고하세요.
3단계: 프로젝트에 API 키 추가
API 키 가져오기에서 앱의 API 키를 생성했습니다. 이제 이 키를 Xcode 프로젝트에 추가합니다.
다음 예에서 YOUR_API_KEY
를 이 API 키로 바꾸세요.
자세한 정보를 확인합니다.
Swift
다음과 같이 API 키를 AppDelegate.swift
에 추가합니다.
- 다음 import 문을 추가합니다.
import GoogleMaps
- API 키를 사용하여
application(_:didFinishLaunchingWithOptions:)
메서드에 다음을 추가합니다.GMSServices.provideAPIKey("YOUR_API_KEY")
- Places API도 사용하고 있다면 여기에 표시된 대로 키를 다시 추가합니다.
GMSPlacesClient.provideAPIKey("YOUR_API_KEY")
Objective-C
다음과 같이 API 키를 AppDelegate.m
에 추가합니다.
- 다음 import 문을 추가합니다.
@import GoogleMaps;
- API 키를 사용하여
application:didFinishLaunchingWithOptions:
메서드에 다음을 추가합니다.[GMSServices provideAPIKey:@"YOUR_API_KEY"];
- Places API도 사용하고 있다면 여기에 표시된 대로 키를 다시 추가합니다.
[GMSPlacesClient provideAPIKey:@"YOUR_API_KEY"];
4단계: 지도 추가하기
Swift
/* * Copyright 2020 Google Inc. All rights reserved. * * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this * file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF * ANY KIND, either express or implied. See the License for the specific language governing * permissions and limitations under the License. */ import UIKit import GoogleMaps class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. // Create a GMSCameraPosition that tells the map to display the // coordinate -33.86,151.20 at zoom level 6. let options = GMSMapViewOptions() options.camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0) options.frame = self.view.bounds let mapView = GMSMapView(options: options) self.view.addSubview(mapView) // Creates a marker in the center of the map. let marker = GMSMarker() marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20) marker.title = "Sydney" marker.snippet = "Australia" marker.map = mapView } }
Objective-C
/* * Copyright 2020 Google Inc. All rights reserved. * * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this * file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF * ANY KIND, either express or implied. See the License for the specific language governing * permissions and limitations under the License. */ #import "ViewController.h" #import <GoogleMaps/GoogleMaps.h> @interface ViewController() @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // Create a GMSCameraPosition that tells the map to display the // coordinate -33.86,151.20 at zoom level 6. GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; options.camera = [GMSCameraPosition cameraWithLatitude:-33.8683 longitude:151.2086 zoom:6]; options.frame = self.view.bounds; GMSMapView *mapView = [[GMSMapView alloc] initWithOptions:options]; [self.view addSubview:mapView]; // Creates a marker in the center of the map. GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); marker.title = @"Sydney"; marker.snippet = @"Australia"; marker.map = mapView; } @end
5단계 (선택사항): API에서 사용하는 URL 스키마 선언
iOS 9 및 Xcode 7부터 앱은 앱의 Info.plist
파일에 스키마를 지정하여 열려는 URL 스키마를 선언할 수 있습니다. iOS용 Maps SDK에서는 사용자가 지도의 Google 로고를 클릭하면 Google 지도 모바일 앱이 열리므로 앱에서 관련 URL 스키마를 선언할 수 있습니다.
iOS용 Maps SDK에서 사용하는 URL 스킴을 선언하려면 Info.plist
에 다음 줄을 추가하세요.
다음 스크린샷은 Xcode 사용자 인터페이스의 구성을 보여줍니다.
위의 선언이 없으면 사용자가 지도에서 Google 로고를 탭할 때 다음과 같은 오류가 발생할 수 있습니다.
-canOpenURL: URL 'comgooglemaps://' - 오류: '이 앱은 comgooglemaps 스키마를 쿼리할 수 없습니다.' -canOpenURL: URL의 경우 실패: 'googlechromes://' - 오류: '이 앱은 googlechromes 스키마를 쿼리할 수 없습니다.'
이러한 오류를 제거하려면 선언을 Info.plist
에 추가합니다.
다음 단계
이제 API 키와 Xcode 프로젝트가 있으므로 앱을 만들고 실행할 수 있습니다. iOS용 Maps SDK는 시작하는 데 도움이 되는 다양한 튜토리얼과 샘플 앱을 제공합니다. 자세한 내용은 다음을 참고하세요.