GMSMapView.h 12 KB

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