GMSMapView.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. //
  2. // GMSMapView.h
  3. // Google Maps SDK for iOS
  4. //
  5. // Copyright 2012 Google Inc.
  6. //
  7. // Usage of this SDK is subject to the Google Maps/Google Earth APIs Terms of
  8. // Service: https://developers.google.com/maps/terms
  9. //
  10. #import <CoreLocation/CoreLocation.h>
  11. #import <UIKit/UIKit.h>
  12. #if __has_feature(modules)
  13. @import GoogleMapsBase;
  14. #else
  15. #import <GoogleMapsBase/GoogleMapsBase.h>
  16. #endif
  17. #import <GoogleMaps/GMSDeprecationMacros.h>
  18. #import <GoogleMaps/GMSMapLayer.h>
  19. #import <GoogleMaps/GMSUISettings.h>
  20. @class GMSCameraPosition;
  21. @class GMSCameraUpdate;
  22. @class GMSCoordinateBounds;
  23. @class GMSIndoorDisplay;
  24. @class GMSMapLayer;
  25. @class GMSMapView;
  26. @class GMSMarker;
  27. @class GMSOverlay;
  28. @class GMSProjection;
  29. GMS_ASSUME_NONNULL_BEGIN
  30. /** Delegate for events on GMSMapView. */
  31. @protocol GMSMapViewDelegate<NSObject>
  32. @optional
  33. /**
  34. * Called before the camera on the map changes, either due to a gesture,
  35. * animation (e.g., by a user tapping on the "My Location" button) or by being
  36. * updated explicitly via the camera or a zero-length animation on layer.
  37. *
  38. * @param gesture If YES, this is occuring due to a user gesture.
  39. */
  40. - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture;
  41. /**
  42. * Called repeatedly during any animations or gestures on the map (or once, if
  43. * the camera is explicitly set). This may not be called for all intermediate
  44. * camera positions. It is always called for the final position of an animation
  45. * or gesture.
  46. */
  47. - (void)mapView:(GMSMapView *)mapView didChangeCameraPosition:(GMSCameraPosition *)position;
  48. /**
  49. * Called when the map becomes idle, after any outstanding gestures or
  50. * animations have completed (or after the camera has been explicitly set).
  51. */
  52. - (void)mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position;
  53. /**
  54. * Called after a tap gesture at a particular coordinate, but only if a marker
  55. * was not tapped. This is called before deselecting any currently selected
  56. * marker (the implicit action for tapping on the map).
  57. */
  58. - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;
  59. /**
  60. * Called after a long-press gesture at a particular coordinate.
  61. *
  62. * @param mapView The map view that was pressed.
  63. * @param coordinate The location that was pressed.
  64. */
  65. - (void)mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;
  66. /**
  67. * Called after a marker has been tapped.
  68. *
  69. * @param mapView The map view that was pressed.
  70. * @param marker The marker that was pressed.
  71. * @return YES if this delegate handled the tap event, which prevents the map
  72. * from performing its default selection behavior, and NO if the map
  73. * should continue with its default selection behavior.
  74. */
  75. - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker;
  76. /**
  77. * Called after a marker's info window has been tapped.
  78. */
  79. - (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker;
  80. /**
  81. * Called after a marker's info window has been long pressed.
  82. */
  83. - (void)mapView:(GMSMapView *)mapView didLongPressInfoWindowOfMarker:(GMSMarker *)marker;
  84. /**
  85. * Called after an overlay has been tapped.
  86. * This method is not called for taps on markers.
  87. *
  88. * @param mapView The map view that was pressed.
  89. * @param overlay The overlay that was pressed.
  90. */
  91. - (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay;
  92. /**
  93. * Called when a marker is about to become selected, and provides an optional
  94. * custom info window to use for that marker if this method returns a UIView.
  95. * If you change this view after this method is called, those changes will not
  96. * necessarily be reflected in the rendered version.
  97. *
  98. * The returned UIView must not have bounds greater than 500 points on either
  99. * dimension. As there is only one info window shown at any time, the returned
  100. * view may be reused between other info windows.
  101. *
  102. * Removing the marker from the map or changing the map's selected marker during
  103. * this call results in undefined behavior.
  104. *
  105. * @return The custom info window for the specified marker, or nil for default
  106. */
  107. - (UIView *GMS_NULLABLE_PTR)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker;
  108. /**
  109. * Called when mapView:markerInfoWindow: returns nil. If this method returns a
  110. * view, it will be placed within the default info window frame. If this method
  111. * returns nil, then the default rendering will be used instead.
  112. *
  113. * @param mapView The map view that was pressed.
  114. * @param marker The marker that was pressed.
  115. * @return The custom view to display as contents in the info window, or nil to
  116. * use the default content rendering instead
  117. */
  118. - (UIView *GMS_NULLABLE_PTR)mapView:(GMSMapView *)mapView markerInfoContents:(GMSMarker *)marker;
  119. /**
  120. * Called when the marker's info window is closed.
  121. */
  122. - (void)mapView:(GMSMapView *)mapView didCloseInfoWindowOfMarker:(GMSMarker *)marker;
  123. /**
  124. * Called when dragging has been initiated on a marker.
  125. */
  126. - (void)mapView:(GMSMapView *)mapView didBeginDraggingMarker:(GMSMarker *)marker;
  127. /**
  128. * Called after dragging of a marker ended.
  129. */
  130. - (void)mapView:(GMSMapView *)mapView didEndDraggingMarker:(GMSMarker *)marker;
  131. /**
  132. * Called while a marker is dragged.
  133. */
  134. - (void)mapView:(GMSMapView *)mapView didDragMarker:(GMSMarker *)marker;
  135. /**
  136. * Called when the My Location button is tapped.
  137. *
  138. * @return YES if the listener has consumed the event (i.e., the default behavior should not occur),
  139. * NO otherwise (i.e., the default behavior should occur). The default behavior is for the
  140. * camera to move such that it is centered on the user location.
  141. */
  142. - (BOOL)didTapMyLocationButtonForMapView:(GMSMapView *)mapView;
  143. /**
  144. * Called when tiles have just been requested or labels have just started rendering.
  145. */
  146. - (void)mapViewDidStartTileRendering:(GMSMapView *)mapView;
  147. /**
  148. * Called when all tiles have been loaded (or failed permanently) and labels have been rendered.
  149. */
  150. - (void)mapViewDidFinishTileRendering:(GMSMapView *)mapView;
  151. /**
  152. * Called when map is stable (tiles loaded, labels rendered, camera idle) and overlay objects have
  153. * been rendered.
  154. */
  155. - (void)mapViewSnapshotReady:(GMSMapView *)mapView;
  156. @end
  157. /**
  158. * Display types for GMSMapView.
  159. */
  160. typedef enum {
  161. /** Basic maps. The default. */
  162. kGMSTypeNormal = 1,
  163. /** Satellite maps with no labels. */
  164. kGMSTypeSatellite,
  165. /** Terrain maps. */
  166. kGMSTypeTerrain,
  167. /** Satellite maps with a transparent label overview. */
  168. kGMSTypeHybrid,
  169. /** No maps, no labels. Display of traffic data is not supported. */
  170. kGMSTypeNone,
  171. } GMSMapViewType;
  172. /**
  173. * Rendering frame rates for GMSMapView.
  174. */
  175. typedef enum {
  176. /** Use the minimum frame rate to conserve battery usage. */
  177. kGMSFrameRatePowerSave,
  178. /**
  179. * Use a median frame rate to provide smoother rendering and conserve processing cycles.
  180. */
  181. kGMSFrameRateConservative,
  182. /**
  183. * Use the maximum frame rate for a device. For low end devices this will be 30 FPS,
  184. * for high end devices 60 FPS.
  185. */
  186. kGMSFrameRateMaximum,
  187. } GMSFrameRate;
  188. /**
  189. * This is the main class of the Google Maps SDK for iOS and is the entry point
  190. * for all methods related to the map.
  191. *
  192. * The map should be instantiated via the convenience constructor
  193. * [GMSMapView mapWithFrame:camera:]. It may also be created with the default
  194. * [[GMSMapView alloc] initWithFrame:] method (wherein its camera will be set to
  195. * a default location).
  196. *
  197. * GMSMapView can only be read and modified from the main thread, similar to all
  198. * UIKit objects. Calling these methods from another thread will result in an
  199. * exception or undefined behavior.
  200. */
  201. @interface GMSMapView : UIView
  202. /** GMSMapView delegate. */
  203. @property(nonatomic, weak) IBOutlet id<GMSMapViewDelegate> GMS_NULLABLE_PTR delegate;
  204. /**
  205. * Controls the camera, which defines how the map is oriented. Modification of
  206. * this property is instantaneous.
  207. */
  208. @property(nonatomic, copy) GMSCameraPosition *camera;
  209. /**
  210. * Returns a GMSProjection object that you can use to convert between screen
  211. * coordinates and latitude/longitude coordinates.
  212. *
  213. * This is a snapshot of the current projection, and will not automatically
  214. * update when the camera moves. It represents either the projection of the last
  215. * drawn GMSMapView frame, or; where the camera has been explicitly set or the
  216. * map just created, the upcoming frame. It will never be nil.
  217. */
  218. @property(nonatomic, readonly) GMSProjection *projection;
  219. /**
  220. * Controls whether the My Location dot and accuracy circle is enabled.
  221. * Defaults to NO.
  222. */
  223. @property(nonatomic, assign, getter=isMyLocationEnabled) BOOL myLocationEnabled;
  224. /**
  225. * If My Location is enabled, reveals where the user location dot is being
  226. * drawn. If it is disabled, or it is enabled but no location data is available,
  227. * this will be nil. This property is observable using KVO.
  228. */
  229. @property(nonatomic, strong, readonly) CLLocation *GMS_NULLABLE_PTR myLocation;
  230. /**
  231. * The marker that is selected. Setting this property selects a particular
  232. * marker, showing an info window on it. If this property is non-nil, setting
  233. * it to nil deselects the marker, hiding the info window. This property is
  234. * observable using KVO.
  235. */
  236. @property(nonatomic, strong) GMSMarker *GMS_NULLABLE_PTR selectedMarker;
  237. /**
  238. * Controls whether the map is drawing traffic data, if available. This is
  239. * subject to the availability of traffic data. Defaults to NO.
  240. */
  241. @property(nonatomic, assign, getter=isTrafficEnabled) BOOL trafficEnabled;
  242. /**
  243. * Controls the type of map tiles that should be displayed. Defaults to
  244. * kGMSTypeNormal.
  245. */
  246. @property(nonatomic, assign) GMSMapViewType mapType;
  247. /**
  248. * Minimum zoom (the farthest the camera may be zoomed out). Defaults to
  249. * kGMSMinZoomLevel. Modified with -setMinZoom:maxZoom:.
  250. */
  251. @property(nonatomic, assign, readonly) float minZoom;
  252. /**
  253. * Maximum zoom (the closest the camera may be to the Earth). Defaults to
  254. * kGMSMaxZoomLevel. Modified with -setMinZoom:maxZoom:.
  255. */
  256. @property(nonatomic, assign, readonly) float maxZoom;
  257. /**
  258. * If set, 3D buildings will be shown where available. Defaults to YES.
  259. *
  260. * This may be useful when adding a custom tile layer to the map, in order to
  261. * make it clearer at high zoom levels. Changing this value will cause all
  262. * tiles to be briefly invalidated.
  263. */
  264. @property(nonatomic, assign, getter=isBuildingsEnabled) BOOL buildingsEnabled;
  265. /**
  266. * Sets whether indoor maps are shown, where available. Defaults to YES.
  267. *
  268. * If this is set to NO, caches for indoor data may be purged and any floor
  269. * currently selected by the end-user may be reset.
  270. */
  271. @property(nonatomic, assign, getter=isIndoorEnabled) BOOL indoorEnabled;
  272. /**
  273. * Gets the GMSIndoorDisplay instance which allows to observe or control
  274. * aspects of indoor data display.
  275. */
  276. @property(nonatomic, strong, readonly) GMSIndoorDisplay *indoorDisplay;
  277. /**
  278. * Gets the GMSUISettings object, which controls user interface settings for the
  279. * map.
  280. */
  281. @property(nonatomic, strong, readonly) GMSUISettings *settings;
  282. /**
  283. * Controls the 'visible' region of the view. By applying padding an area
  284. * around the edge of the view can be created which will contain map data
  285. * but will not contain UI controls.
  286. *
  287. * If the padding is not balanced, the visual center of the view will move as
  288. * appropriate. Padding will also affect the |projection| property so the
  289. * visible region will not include the padding area. GMSCameraUpdate
  290. * fitToBounds will ensure that both this padding and any padding requested
  291. * will be taken into account.
  292. *
  293. * This property may be animated within a UIView-based animation block.
  294. */
  295. @property(nonatomic, assign) UIEdgeInsets padding;
  296. /**
  297. * Defaults to YES. If set to NO, GMSMapView will generate accessibility
  298. * elements for overlay objects, such as GMSMarker and GMSPolyline.
  299. *
  300. * This property is as per the informal UIAcessibility protocol, except for the
  301. * default value of YES.
  302. */
  303. @property(nonatomic) BOOL accessibilityElementsHidden;
  304. /**
  305. * Accessor for the custom CALayer type used for the layer.
  306. */
  307. @property(nonatomic, readonly, retain) GMSMapLayer *layer;
  308. /**
  309. * Controls the rendering frame rate.
  310. * Default value is kGMSFrameRateMaximum.
  311. */
  312. @property(nonatomic, assign) GMSFrameRate preferredFrameRate;
  313. /**
  314. * Builds and returns a GMSMapView, with a frame and camera target.
  315. */
  316. + (instancetype)mapWithFrame:(CGRect)frame camera:(GMSCameraPosition *)camera;
  317. /**
  318. * Tells this map to power up its renderer. This is optional and idempotent.
  319. *
  320. * This method is obsolete and deprecated and will be removed in a future release.
  321. */
  322. - (void)startRendering __GMS_AVAILABLE_BUT_DEPRECATED;
  323. /**
  324. * Tells this map to power down its renderer. This is optional and idempotent.
  325. *
  326. * This method is obsolete and deprecated and will be removed in a future release.
  327. */
  328. - (void)stopRendering __GMS_AVAILABLE_BUT_DEPRECATED;
  329. /**
  330. * Clears all markup that has been added to the map, including markers,
  331. * polylines and ground overlays. This will not clear the visible location dot
  332. * or reset the current mapType.
  333. */
  334. - (void)clear;
  335. /**
  336. * Sets |minZoom| and |maxZoom|. This method expects the minimum to be less than
  337. * or equal to the maximum, and will throw an exception with name
  338. * NSRangeException otherwise.
  339. */
  340. - (void)setMinZoom:(float)minZoom maxZoom:(float)maxZoom;
  341. /**
  342. * Build a GMSCameraPosition that presents |bounds| with |padding|. The camera
  343. * will have a zero bearing and tilt (i.e., facing north and looking directly at
  344. * the Earth). This takes the frame and padding of this GMSMapView into account.
  345. *
  346. * If the bounds is invalid this method will return a nil camera.
  347. */
  348. - (GMSCameraPosition *GMS_NULLABLE_PTR)cameraForBounds:(GMSCoordinateBounds *)bounds
  349. insets:(UIEdgeInsets)insets;
  350. /**
  351. * Changes the camera according to |update|.
  352. * The camera change is instantaneous (with no animation).
  353. */
  354. - (void)moveCamera:(GMSCameraUpdate *)update;
  355. @end
  356. /**
  357. * Accessibility identifier for the compass button.
  358. */
  359. extern NSString *const kGMSAccessibilityCompass;
  360. /**
  361. * Accessibility identifier for the "my location" button.
  362. */
  363. extern NSString *const kGMSAccessibilityMyLocation;
  364. GMS_ASSUME_NONNULL_END