GMSMapView가 생성되면 대리자를 뷰 컨트롤러로 설정할 수 있습니다. GMSMapViewDelegate는 선택적 메서드만 제공합니다. 특정 이벤트를 리슨하려면 관련 메서드를 구현해야 합니다.
Swift
overridefuncloadView(){super.loadView()letcamera=GMSCameraPosition.camera(withLatitude:1.285,longitude:103.848,zoom:12)letmapView=GMSMapView.map(withFrame:.zero,camera:camera)mapView.delegate=selfself.view=mapView}// MARK: GMSMapViewDelegatefuncmapView(_mapView:GMSMapView,didTapAtcoordinate:CLLocationCoordinate2D){print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")}
Objective-C
-(void)loadView{[superloadView];GMSCameraPosition*camera=[GMSCameraPositioncameraWithLatitude:1.285longitude:103.848zoom:12];GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZerocamera:camera];mapView.delegate=self;self.view=mapView;}#pragma mark - GMSMapViewDelegate-(void)mapView:(GMSMapView*)mapViewdidTapAtCoordinate:(CLLocationCoordinate2D)coordinate{NSLog(@"You tapped at %f,%f",coordinate.latitude,coordinate.longitude);}
카메라 위치
GMSMapViewDelegate를 사용하면 지도를 렌더링하는 데 사용되는 카메라 위치의 변경사항을 수신할 수 있습니다. 세 가지 고유한 이벤트가 있습니다.
mapView:willMove:는 카메라 위치가 곧 변경됨을 나타냅니다.
gesture 인수가 YES로 설정된 경우 사용자가 GMSMapView에서 팬 또는 기울이기와 같은 자연스러운 동작을 수행했기 때문입니다.
그렇지 않으면 NO는 프로그래매틱 변경의 일부임을 나타냅니다(예: animateToCameraPosition:과 같은 메서드를 사용하거나 지도의 레이어를 직접 업데이트). 사용자가 내 위치 또는 나침반 버튼을 탭한 경우에도 NO일 수 있습니다. 이러한 버튼은 카메라를 변경하는 애니메이션을 생성합니다.
이 메서드는 mapView:idleAtCameraPosition:가 호출되기 전에 여러 번 호출될 수 있습니다. 하지만 이는 일반적으로 애니메이션과 동작이 동시에 발생하는 경우에만 발생합니다. 예를 들어 동작은 현재 애니메이션을 취소하고 mapView:willMove:를 두 번째로 호출합니다.
mapView:didChangeCameraPosition:는 동작이나 애니메이션 중에 반복적으로 호출되며 항상 mapView:willMove: 호출 후에 호출됩니다. 중간 카메라 위치가 전달됩니다.
마지막으로 mapView:idleAtCameraPosition:는 GMSMapView의 카메라 위치가 유휴 상태가 되면 호출되어 관련 카메라 위치를 지정합니다.
이 시점에서 모든 애니메이션과 제스처가 중단됩니다.
애플리케이션은 이 이벤트를 사용하여 카메라가 변경될 때마다 콘텐츠를 다시 로드하는 대신 GMSMapView에 표시되는 마커나 기타 콘텐츠의 새로고침을 트리거할 수 있습니다.
예를 들어 애플리케이션은 이동 시 GMSMapView를 지우고 카메라가 정지하는 위치를 리버스 지오코딩할 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eThe Maps SDK for iOS allows you to listen to events like camera changes and marker taps by implementing the \u003ccode\u003eGMSMapViewDelegate\u003c/code\u003e protocol.\u003c/p\u003e\n"],["\u003cp\u003eYou can track camera position changes using events such as \u003ccode\u003ewillMove\u003c/code\u003e, \u003ccode\u003edidChangeCameraPosition\u003c/code\u003e, and \u003ccode\u003eidleAtCameraPosition\u003c/code\u003e to update map content dynamically.\u003c/p\u003e\n"],["\u003cp\u003eRespond to clicks on businesses and points of interest (POIs) using dedicated event handling mechanisms.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the \u003ccode\u003eGMSMapViewDelegate\u003c/code\u003e reference for a comprehensive list of available events and methods.\u003c/p\u003e\n"]]],["To listen to events on the Maps SDK for iOS, implement the `GMSMapViewDelegate` protocol in your view controller. Set the `GMSMapView`'s delegate to your view controller during creation. Implement relevant methods from the `GMSMapViewDelegate` to listen to specific events. For camera position changes, use `mapView:willMove:`, `mapView:didChangeCameraPosition:`, and `mapView:idleAtCameraPosition:`. The example provided demonstrates how to clear the map on move and reverse geocode the final camera position.\n"],null,["\u003cbr /\u003e\n\nSelect platform: [Android](/maps/documentation/android-sdk/events \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/events \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/events \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nUsing the Maps SDK for iOS, you can listen to events that occur on the\nmap, such as camera change events or marker tap events.\n\nIntroduction\n\nTo listen to events, you must implement the\n[`GMSMapViewDelegate`](/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate) protocol. Typically, you implement\nthis protocol on the view controller that displays the map. Below is an example:\n\n\nSwift \n\n```swift\nimport GoogleMaps\n\nclass Events: UIViewController, GMSMapViewDelegate {\n // ...\n}\n \n```\n\nObjective-C \n\n```objective-c\n@import GoogleMaps;\n\n@interface Events : UIViewController \u003cGMSMapViewDelegate\u003e\n\n@end\n \n```\n\n\u003cbr /\u003e\n\nWhen the `GMSMapView` is created, you can set its delegate to your view\ncontroller. The `GMSMapViewDelegate` provides only optional methods. To listen\nto any particular event, you must implement the relevant method.\n\n\nSwift \n\n```swift\noverride func loadView() {\n super.loadView()\n let camera = GMSCameraPosition.camera(\n withLatitude: 1.285,\n longitude: 103.848,\n zoom: 12\n )\n let mapView = GMSMapView.map(withFrame: .zero, camera: camera)\n mapView.delegate = self\n self.view = mapView\n}\n\n// MARK: GMSMapViewDelegate\n\nfunc mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {\n print(\"You tapped at \\(coordinate.latitude), \\(coordinate.longitude)\")\n}\n \n```\n\nObjective-C \n\n```objective-c\n- (void)loadView {\n [super loadView];\n GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285\n longitude:103.848\n zoom:12];\n GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];\n mapView.delegate = self;\n self.view = mapView;\n}\n\n#pragma mark - GMSMapViewDelegate\n\n- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate {\n NSLog(@\"You tapped at %f,%f\", coordinate.latitude, coordinate.longitude);\n}\n \n```\n\n\u003cbr /\u003e\n\nCamera position\n\nUsing the `GMSMapViewDelegate`, you can listen to changes to the camera position\nused to render the map. There are three distinct events.\n\n- `mapView:willMove:` indicates that the camera position is about to change.\n If the `gesture` argument is set to `YES`, this is due to a user performing\n a natural gesture on the `GMSMapView`, such as a pan or tilt.\n Otherwise, `NO` indicates that this is part of a programmatic change -\n for example, via methods such as `animateToCameraPosition:` or updating the\n map's layer directly. This may also be `NO` if a user has tapped on the My\n Location or compass buttons, which generate animations that change the\n camera.\n\n This method may be called several times before\n `mapView:idleAtCameraPosition:` is invoked, although this typically\n happens only if animations and gestures occur at the same time - a gesture\n will cancel any current animation, for instance, and will call\n `mapView:willMove:` a second time.\n- `mapView:didChangeCameraPosition:` is called repeatedly during a gesture or\n animation, always after a call to `mapView:willMove:`. It is passed the\n intermediate camera position.\n\n- Finally, `mapView:idleAtCameraPosition:` is invoked once the camera position\n on `GMSMapView` becomes idle, and specifies the relevant camera position.\n At this point, all animations and gestures have stopped.\n\n Applications can use this event to trigger a refresh of markers or other\n content being displayed on the `GMSMapView`, rather than, for example,\n reloading the content on every camera change.\n\nFor example, an application can clear the `GMSMapView` on move, and then\nreverse geocode the position the camera comes to rest on.\n\n\nSwift \n\n```swift\nlet geocoder = GMSGeocoder()\n\nfunc mapView(_ mapView: GMSMapView, willMove gesture: Bool) {\n mapView.clear()\n}\n\nfunc mapView(_ mapView: GMSMapView, idleAt cameraPosition: GMSCameraPosition) {\n geocoder.reverseGeocodeCoordinate(cameraPosition.target) { (response, error) in\n guard error == nil else {\n return\n }\n\n if let result = response?.firstResult() {\n let marker = GMSMarker()\n marker.position = cameraPosition.target\n marker.title = result.lines?[0]\n marker.snippet = result.lines?[1]\n marker.map = mapView\n }\n }\n }\n \n```\n\nObjective-C \n\n```objective-c\nGMSGeocoder *geocoder;\n\n- (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {\n [mapView clear];\n}\n\n- (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)cameraPosition {\n id handler = ^(GMSReverseGeocodeResponse *response, NSError *error) {\n if (error != nil) {\n return;\n }\n GMSReverseGeocodeResult *result = response.firstResult;\n GMSMarker *marker = [GMSMarker markerWithPosition:cameraPosition.target];\n marker.title = result.lines[0];\n marker.snippet = result.lines[1];\n marker.map = mapView;\n };\n [geocoder reverseGeocodeCoordinate:cameraPosition.target completionHandler:handler];\n}\n \n```\n\n\u003cbr /\u003e\n\nEvents on businesses and other points of interest\n\nBy default, points of interest (POIs) appear on the base map along with their corresponding icons. POIs include parks, schools, government buildings, and more, as well as business POIs such as shops, restaurants, and hotels.\n\nYou can respond to click events on a POI. See the guide to\n[businesses and other points of interest](/maps/documentation/ios-sdk/poi).\n\nOther events\n\nTo learn about the full list of methods on `GMSMapViewDelegate`, see\n[the reference guide](/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate)."]]