组合库
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Combine 是
框架,通过组合事件处理运算符来处理异步事件。
Combine 通过集中事件处理代码让您的代码更易于阅读和维护。
GoogleMapsPlatformCombine 库
是一个 Swift 库,会返回
Publishers
和 Places SDK for iOS,这样您就可以利用
丰富的 Combine 功能。
安装
请参阅
GoogleMapsPlatformCombine 库
了解最新的系统要求和安装说明。
用法示例
GoogleMapsPlatformCombine 库包含
GMSMapViewPublisher
类
,其中包含可让您订阅地图发出的事件的发布商属性。
以下示例展示了如何配置要订阅的 GMSMapViewPublisher
实例
摄像头更改事件:
let publisher = GMSMapViewPublisher(mapView: mapView)
publisher.didChangeCameraPosition.sink { cameraPosition in
print("Camera position at \(cameraPosition.target)")
}
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eGoogleMapsPlatformCombine is a Swift library that integrates the Maps SDK for iOS and Places SDK for iOS with Apple's Combine framework.\u003c/p\u003e\n"],["\u003cp\u003eThis library provides Publishers for various SDK functionalities, allowing developers to leverage Combine's features for asynchronous event handling.\u003c/p\u003e\n"],["\u003cp\u003eBy using GoogleMapsPlatformCombine, developers can simplify their code and centralize event-processing logic for Google Maps and Places SDKs within their applications.\u003c/p\u003e\n"],["\u003cp\u003eA practical example demonstrates subscribing to camera change events on a \u003ccode\u003eGMSMapView\u003c/code\u003e using the \u003ccode\u003eGMSMapViewPublisher\u003c/code\u003e and Combine's \u003ccode\u003esink\u003c/code\u003e operator.\u003c/p\u003e\n"]]],["The content introduces the GoogleMapsPlatformCombine library, which utilizes Apple's Combine framework for handling asynchronous events within the Google Maps and Places SDKs for iOS. It leverages `Publishers` to manage events. A key action is demonstrated through the `GMSMapViewPublisher` class, allowing users to subscribe to map events. An example illustrates how to monitor camera position changes using the `didChangeCameraPosition` publisher. Installation instructions and further details are available on the library's GitHub page.\n"],null,["[Combine](https://developer.apple.com/documentation/combine) is a\nframework for handling asynchronous events by combining event-processing operators.\nCombine makes your code easier to read and maintain by centralizing your event-processing code.\n\nThe [GoogleMapsPlatformCombine library](https://github.com/googlemaps/ios-combine)\nis a Swift library that returns\n[`Publishers`](https://developer.apple.com/documentation/combine/publisher)\nfor the Maps SDK for iOS and Places SDK for iOS so that you can take advantage\nof the rich set of Combine features.\n\nInstallation See the [GoogleMapsPlatformCombine library](https://github.com/googlemaps/ios-combine) documentation on GitHub for the latest system requirements and installation instructions.\n\n\u003cbr /\u003e\n\nExample Usage\n\nThe GoogleMapsPlatformCombine library includes the\n[`GMSMapViewPublisher`](https://github.com/googlemaps/ios-combine/blob/main/Sources/Maps/GMSMapViewPublisher.swift) class\nwhich contains publisher properties that let you subscribe to events emitted by the map.\n\nThe following example configures a `GMSMapViewPublisher` instance to subscribe to\ncamera change events: \n\n```yaml\nlet publisher = GMSMapViewPublisher(mapView: mapView)\npublisher.didChangeCameraPosition.sink { cameraPosition in\n print(\"Camera position at \\(cameraPosition.target)\")\n}\n```\n\nWhat's next\n\n- View the [Combine library](https://github.com/googlemaps/ios-combine) GitHub project page."]]