### Get Started with Google Maps Platform Source: https://developers.google.com/maps/documentation/ios-sdk?hl=fr Learn how to create an account, generate an API key, and start building maps with the Google Maps Platform. ```text map ``` -------------------------------- ### Example: Create and Configure GMSURLTileLayer Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSURLTileLayer.html This example demonstrates how to create a GMSTileURLConstructor, initialize a GMSURLTileLayer with it, set a custom user agent, and assign it to a map. ```Objective-C GMSTileURLConstructor constructor = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) { NSString *URLStr = [NSString stringWithFormat:@"https://example.com/%d/%d/%d.png", x, y, zoom]; return [NSURL URLWithString:URLStr]; }; GMSTileLayer *layer = [GMSURLTileLayer tileLayerWithURLConstructor:constructor]; layer.userAgent = @"SDK user agent"; layer.map = map; ``` -------------------------------- ### Link Frameworks and Libraries for Manual Installation Source: https://developers.google.com/maps/documentation/ios-sdk/start Add these frameworks and libraries in the 'Link Binary with Libraries' section of your application's target Build Phases for manual installation. ```bash Accelerate.framework Contacts.framework CoreData.framework CoreGraphics.framework CoreImage.framework CoreLocation.framework CoreTelephony.framework CoreText.framework GLKit.framework ImageIO.framework libc++.tbd libz.tbd Metal.framework MetricKit.framework OpenGLES.framework (Only if you are using OpenGL) QuartzCore.framework ``` -------------------------------- ### Install Pods Source: https://developers.google.com/maps/documentation/ios-sdk/config Command to install dependencies defined in the Podfile. ```bash pod install ``` -------------------------------- ### Example: Create and Configure GMSURLTileLayer Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSURLTileLayer?hl=es-419 This example demonstrates how to create a GMSTileURLConstructor, initialize a GMSURLTileLayer with it, set a custom user agent, and add the layer to a map. ```Objective-C GMSTileURLConstructor constructor = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) { NSString *URLStr = [NSString stringWithFormat:@"https://example.com/%d/%d/%d.png", x, y, zoom]; return [NSURL URLWithString:URLStr]; }; GMSTileLayer *layer = [GMSURLTileLayer tileLayerWithURLConstructor:constructor]; layer.userAgent = @"SDK user agent"; layer.map = map; ``` -------------------------------- ### GMSURLTileLayer Example Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes?hl=tr Fetches tiles based on URLs from a GMSTileURLConstructor. This class may not be subclassed. ```objc GMSTileURLConstructor constructor = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) { NSString *URLStr = \ [NSString stringWithFormat:@"https://example.com/%d/%d/%d.png", x, y, zoom]; return [NSURL URLWithString:URLStr]; }; GMSTileLayer *layer = \ [GMSURLTileLayer tileLayerWithURLConstructor:constructor]; layer.userAgent = @"SDK user agent"; layer.map = map; ``` -------------------------------- ### Open the sample project in Xcode Source: https://developers.google.com/maps/documentation/ios-sdk/examples/basic-map Commands to navigate to the sample directory and open the Xcode project file. ```bash cd maps-sdk-for-ios-samples/GoogleMaps-Swift open GoogleMapsSwiftXCFrameworkDemos.xcodeproj ``` ```bash cd maps-sdk-for-ios-samples-main/GoogleMaps open GoogleMapsDemos.xcodeproj ``` -------------------------------- ### Map View Marker Drag Start Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate.html?hl=de Called when a user begins dragging a marker on the map. No setup required. ```swift optional func mapView(_ mapView: GMSMapView, didBeginDragging marker: GMSMarker) ``` ```objective-c - (void)mapView:(nonnull GMSMapView *)mapView didBeginDraggingMarker:(nonnull GMSMarker *)marker; ``` -------------------------------- ### Map View Tile Rendering Start Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate.html?hl=de Called when the map view begins rendering tiles or labels. No setup required. ```swift optional func mapViewDidStartTileRendering(_ mapView: GMSMapView) ``` ```objective-c - (void)mapViewDidStartTileRendering:(nonnull GMSMapView *)mapView; ``` -------------------------------- ### Get SDK Long Version Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices.html?hl=es Returns the long version string for the current release of the Google Maps SDK for iOS, for example, '1.0.0 (102.1)'. ```Swift class func sdkLongVersion() -> String ``` ```Objective-C + (nonnull NSString *)SDKLongVersion; ``` -------------------------------- ### GMSPanoramaCamera Initializers and Convenience Constructors Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSPanoramaCamera.html Explains how to initialize and configure GMSPanoramaCamera using various methods. ```APIDOC ## GMSPanoramaCamera Initializers and Convenience Constructors ### Description `GMSPanoramaCamera` controls the viewing direction of a `GMSPanoramaView`. It is configured using properties such as `orientation`, `zoom`, and `FOV`. The `initWithOrientation:zoom:FOV:` initializer sets these properties, with values clamped to acceptable ranges. Convenience constructors, like `cameraWithHeading:pitch:zoom:` or `cameraWithOrientation:zoom:FOV:`, allow setting camera properties, including heading, pitch, and FOV which has a range between 1 and 160, and the zoom which is between 1 and 5. ### Initializers #### `initWithOrientation:zoom:FOV:` Initializes a `GMSPanoramaCamera` with the specified orientation, zoom level, and Field of View (FOV). ### Convenience Constructors #### `cameraWithHeading:pitch:zoom:` Creates a `GMSPanoramaCamera` with the specified heading, pitch, and zoom level. #### `cameraWithOrientation:zoom:FOV:` Creates a `GMSPanoramaCamera` with the specified orientation, zoom level, and Field of View (FOV). ### Parameters #### Zoom - **zoom** (Float) - The zoom level. Range: 1 to 5. #### FOV (Field of View) - **fov** (Float) - The Field of View. Range: 1 to 160. ``` -------------------------------- ### Install CocoaPods Source: https://developers.google.com/maps/documentation/ios-sdk/config Command to install the CocoaPods dependency manager on macOS. ```bash sudo gem install cocoapods ``` -------------------------------- ### Clone the sample app repository Source: https://developers.google.com/maps/documentation/ios-sdk/code-samples Use git clone to get the sample app repository from GitHub. This command downloads all the necessary files to your local machine. ```bash git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.git ``` -------------------------------- ### Get Default Level Index - Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSIndoorBuilding.html?hl=fr Gets the index of the default level within the building's levels array. ```objectivec @property (nonatomic, readonly) NSUInteger defaultLevelIndex; ``` -------------------------------- ### Get Default Level Index - Swift Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSIndoorBuilding.html?hl=fr Gets the index of the default level within the building's levels array. ```swift var defaultLevelIndex: UInt { get } ``` -------------------------------- ### Navigate to the GoogleMaps directory (Swift) Source: https://developers.google.com/maps/documentation/ios-sdk/code-samples Change directory to the Swift sample app and open the Xcode project. This prepares the project for API key integration. ```bash cd maps-sdk-for-ios-samples/GoogleMaps-Swift open GoogleMapsSwiftXCFrameworkDemos.xcodeproj ``` -------------------------------- ### Get Camera Heading - Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Structs/GMSOrientation.html?hl=ko Retrieves the camera's horizontal angle in degrees. Use this to get the current heading of the camera. ```objective-c const CLLocationDirection heading ``` -------------------------------- ### Initialize SDKs with API Key Source: https://developers.google.com/maps/documentation/ios-sdk/current-place-tutorial Provide your API key to the GMSPlacesClient and GMSServices within the application launch method. ```swift GMSPlacesClient.provideAPIKey("YOUR_API_KEY") GMSServices.provideAPIKey("YOUR_API_KEY") ``` -------------------------------- ### Navigate to the GoogleMaps directory (Objective-C) Source: https://developers.google.com/maps/documentation/ios-sdk/code-samples Change directory to the Objective-C sample app and open the Xcode project. This prepares the project for API key integration. ```bash cd maps-sdk-for-ios-samples-main/GoogleMaps open GoogleMapsDemos.xcodeproj ``` -------------------------------- ### Get Camera Heading - Swift Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Structs/GMSOrientation.html?hl=ko Retrieves the camera's horizontal angle in degrees. Use this to get the current heading of the camera. ```swift var heading: CLLocationDirection { get } ``` -------------------------------- ### Show an info window for a marker Source: https://developers.google.com/maps/documentation/ios-sdk/code-samples?hl=pt-br This example demonstrates how to display an info window when a marker is tapped. Ensure you have a marker added to the map before implementing this. ```swift func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool { // This method is called when a marker is tapped. // You can customize the info window content here. mapView.selectedMarker = marker return true } ``` -------------------------------- ### Get Camera Pitch - Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Structs/GMSOrientation.html?hl=ko Retrieves the camera's vertical angle in degrees from the horizon. Use this to get the current pitch of the camera. ```objective-c const double pitch ``` -------------------------------- ### Initialize Map and Location Services in Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/current-place-tutorial?hl=pt-br Setup for CLLocationManager, GMSMapView, and GMSPlacesClient within a UIViewController. ```Objective-C #import "MapViewController.h" #import "PlacesViewController.h" @import CoreLocation; @import GooglePlaces; @import GoogleMaps; @interface MapViewController () @end @implementation MapViewController { CLLocationManager *locationManager; CLLocation * _Nullable currentLocation; GMSMapView *mapView; GMSPlacesClient *placesClient; float preciseLocationZoomLevel; float approximateLocationZoomLevel; // An array to hold the list of likely places. NSMutableArray *likelyPlaces; // The currently selected place. GMSPlace * _Nullable selectedPlace; } - (void)viewDidLoad { [super viewDidLoad]; preciseLocationZoomLevel = 15.0; approximateLocationZoomLevel = 15.0; // Initialize the location manager. locationManager = [[CLLocationManager alloc] init]; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager requestWhenInUseAuthorization]; locationManager.distanceFilter = 50; [locationManager startUpdatingLocation]; locationManager.delegate = self; placesClient = [GMSPlacesClient sharedClient]; // A default location to use when location permission is not granted. CLLocationCoordinate2D defaultLocation = CLLocationCoordinate2DMake(-33.869405, 151.199); // Create a map. float zoomLevel = locationManager.accuracyAuthorization == CLAccuracyAuthorizationFullAccuracy ? preciseLocationZoomLevel : approximateLocationZoomLevel; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:defaultLocation.latitude longitude:defaultLocation.longitude zoom:zoomLevel]; mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; mapView.settings.myLocationButton = YES; mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; mapView.myLocationEnabled = YES; // Add the map to the view, hide it until we've got a location update. [self.view addSubview:mapView]; mapView.hidden = YES; [self listLikelyPlaces]; } ``` -------------------------------- ### Get Camera Pitch - Swift Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Structs/GMSOrientation.html?hl=ko Retrieves the camera's vertical angle in degrees from the horizon. Use this to get the current pitch of the camera. ```swift var pitch: Double { get } ``` -------------------------------- ### GMSMapStyle Initialization Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapStyle.html?hl=ja Methods to create a GMSMapStyle instance from either a JSON string or a file URL. ```APIDOC ## +styleWithJSONString:error: ### Description Creates a style using a string containing JSON. Returns nil and populates error if the style is invalid. ### Method Class Method ### Parameters - **style** (NSString) - Required - A string containing the JSON style definition. - **error** (NSError**) - Optional - A pointer to an error object to populate if initialization fails. --- ## +styleWithContentsOfFileURL:error: ### Description Creates a style using a file containing JSON. Returns nil and populates error if the style is invalid, the file cannot be read, or the URL is not a file URL. ### Method Class Method ### Parameters - **fileURL** (NSURL) - Required - The URL of the file containing the JSON style definition. - **error** (NSError**) - Optional - A pointer to an error object to populate if initialization fails. ``` -------------------------------- ### Example GeoJSON Feature Entry Source: https://developers.google.com/maps/documentation/ios-sdk/dds-datasets/style-data-features This is an example of a GeoJSON feature entry for a park in New York City, illustrating the structure of properties and geometry data. ```json { "type": "Feature", "properties": { "jurisdiction": "DPR", "mapped": "False", "zipcode": "11356", "acres": "0.05", "location": "College Pl., College Pt. Blvd., bet. 11 Ave. and 12 Ave.", "nys_assembly": "27", "councildistrict": "19", "url": "http://www.nycgovparks.org/parks/Q042/", "typecategory": "Triangle/Plaza", "us_congress": "14", "eapply": "Poppenhusen Park", "parentid": "Q-07", "gispropnum": "Q042", "retired": "false", "communityboard": "407", "objectid": "6248", "globalid": "F4810079-CBB9-4BE7-BBFA-B3C0C35D5DE5", "name311": "Poppenhusen Park", "department": "Q-07", "pip_ratable": "true", "subcategory": "Sitting Area/Triangle/Mall", "precinct": "109", "permit": "true", "acquisitiondate": null, "omppropid": "Q042", "gisobjid": "100000301", "signname": "Poppenhusen Park", "address": null, "permitparent": "Q-07", "class": "PARK", "nys_senate": "11", "permitdistrict": "Q-07", "borough": "Q", "waterfront": "false" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -73.84575702371716, 40.78796240884273 ], [ -73.84593393292693, 40.78796857347548 ], [ -73.84577256469657, 40.787651355629556 ], [ -73.84575702371716, 40.78796240884273 ] ] ] ] } } ``` -------------------------------- ### GMSMapStyle Initialization Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapStyle.html?hl=fr Methods for creating a GMSMapStyle instance from either a JSON string or a local file URL. ```APIDOC ## +styleWithJSONString:error: ### Description Creates a style using a string containing JSON. Returns nil and populates error if the style is invalid. ### Method Class Method ### Parameters - **style** (NSString) - Required - A string containing the JSON style definition. - **error** (NSError**) - Optional - A pointer to an error object to be populated if initialization fails. --- ## +styleWithContentsOfFileURL:error: ### Description Creates a style using a file containing JSON. Returns nil and populates error if the style is invalid, the file cannot be read, or the URL is not a file URL. ### Method Class Method ### Parameters - **fileURL** (NSURL) - Required - The URL of the file containing the JSON style definition. - **error** (NSError**) - Optional - A pointer to an error object to be populated if initialization fails. ``` -------------------------------- ### Initialize Map View and Camera Source: https://developers.google.com/maps/documentation/ios-sdk/examples/draw-polygons?hl=bn Sets up the GMSMapView with a specified camera position. The delegate is set to enable interaction. ```objc #import "GoogleMapsDemos/Samples/PolygonsViewController.h" #import @interface PolygonsViewController () @property(nonatomic) GMSPolygon *polygonOfNewYork; @property(nonatomic) GMSPolygon *polygonOfNorthCarolina; @end @implementation PolygonsViewController - (void)viewDidLoad { [super viewDidLoad]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:39.13006 longitude:-77.508545 zoom:4]; GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView.delegate = self; // needed for didTapOverlay delegate method self.view = mapView; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Create renderer related objects after view appears, so a renderer will be available; otherwise, // behavior is undefined (may result in null ptr derefs). GMSMapView *mapView = (GMSMapView *)self.view; // Create the first polygon. GMSPolygon *polygon = [[GMSPolygon alloc] init]; polygon.path = [self pathOfNewYorkState]; polygon.holes = @[ [self pathOfNewYorkStateHole] ]; polygon.title = @"New York"; polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.2f]; polygon.strokeColor = [UIColor blackColor]; polygon.strokeWidth = 2; polygon.tappable = YES; polygon.map = mapView; self.polygonOfNewYork = polygon; // Copy the existing polygon and its settings and use it as a base for the second polygon. polygon = [polygon copy]; polygon.title = @"North Carolina"; polygon.path = [self pathOfNorthCarolina]; polygon.fillColor = [UIColor colorWithRed:0 green:0.25 blue:0 alpha:0.5]; polygon.map = mapView; self.polygonOfNorthCarolina = polygon; } - (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay { // When a polygon is tapped, randomly change its fill color to a new hue. if ([overlay isKindOfClass:[GMSPolygon class]]) { GMSPolygon *polygon = (GMSPolygon *)overlay; CGFloat hue = (((float)arc4random() / 0x100000000) * 1.0f); polygon.fillColor = [UIColor colorWithHue:hue saturation:1 brightness:1 alpha:0.5]; } } - (GMSPath *)pathOfNewYorkState { GMSMutablePath *path = [GMSMutablePath path]; [path addLatitude:42.5142 longitude:-79.7624]; [path addLatitude:42.7783 longitude:-79.0672]; [path addLatitude:42.8508 longitude:-78.9313]; [path addLatitude:42.9061 longitude:-78.9024]; ``` -------------------------------- ### GMSMapStyle Initialization Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapStyle.html?hl=id Methods to create a GMSMapStyle instance from a JSON string or a file URL. ```APIDOC ## +styleWithJSONString:error: ### Description Creates a style using a string containing JSON. Returns nil and populates error if the style is invalid. ### Method Class Method ### Parameters - **style** (NSString) - Required - A string containing the JSON style definition. - **error** (NSError**) - Optional - A pointer to an error object to be populated if the style is invalid. --- ## +styleWithContentsOfFileURL:error: ### Description Creates a style using a file containing JSON. Returns nil and populates error if the style is invalid, the file cannot be read, or the URL is not a file URL. ### Method Class Method ### Parameters - **fileURL** (NSURL) - Required - The URL of the file containing the JSON style definition. - **error** (NSError**) - Optional - A pointer to an error object to be populated if the style is invalid or the file is inaccessible. ``` -------------------------------- ### GMSFeatureLayer style Example Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSFeatureLayer.html?hl=de Example demonstrating how to apply dynamic styling to a GMSFeatureLayer based on a set of selected place IDs. The style is updated when selectedPlaceIDs or the style properties change. ```swift var selectedPlaceIDs = Set() var style = FeatureStyle(fill: .red, stroke: .clear, strokeWidth: 0) layer.style = { feature in selectedPlaceIDs.contains(feature.placeID) ? style : nil } selectedPlaceIDs.insert("foo") style = FeatureStyle(fill: .clear, stroke: .blue, strokeWidth: 1.5) layer.style = { feature in selectedPlaceIDs.contains(feature.placeID) ? style : nil } ``` -------------------------------- ### panoramaViewDidStartRendering: Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSPanoramaViewDelegate?hl=fa Called when rendering starts. ```APIDOC ## panoramaViewDidStartRendering: ### Description Called when the panorama tiles for the current view have just been requested and are beginning to load. ### Parameters - **panoramaView** (GMSPanoramaView) - The panorama view instance. ``` -------------------------------- ### GMSMapStyle Initialization Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapStyle.html?hl=ru Methods to create a GMSMapStyle instance from a JSON string or a file URL. ```APIDOC ## +styleWithJSONString:error: ### Description Creates a style using a string containing JSON. Returns nil and populates error if the style is invalid. ### Method Class Method ### Parameters #### Request Body - **style** (NSString) - Required - A string containing the JSON style definition. - **error** (NSError**) - Optional - A pointer to an error object to be populated if the style is invalid. --- ## +styleWithContentsOfFileURL:error: ### Description Creates a style using a file containing JSON. Returns nil and populates error if the style is invalid, the file cannot be read, or the URL is not a file URL. ### Method Class Method ### Parameters #### Request Body - **fileURL** (NSURL) - Required - The URL of the file containing the JSON style definition. - **error** (NSError**) - Optional - A pointer to an error object to be populated if the style is invalid or the file is inaccessible. ``` -------------------------------- ### Get GMSPath count Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSPath.html?hl=de Returns the number of coordinates in the path. ```Swift func count() -> UInt ``` ```Objective-C - (NSUInteger)count; ``` -------------------------------- ### Initialize with frame or coder (Deprecated) Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=vi Deprecated initialization methods. Use init or initWithOptions: instead. ```Swift convenience init(frame: CGRect) ``` ```Objective-C - (instancetype)initWithFrame:(CGRect)frame __GMS_AVAILABLE_BUT_DEPRECATED_MSG("Use -init or -initWithOptions: instead."); ``` ```Swift convenience init?(coder: NSCoder) ``` ```Objective-C - (nullable instancetype)initWithCoder:(NSCoder *)coder __GMS_AVAILABLE_BUT_DEPRECATED_MSG("Use -init or -initWithOptions: instead."); ``` -------------------------------- ### GMSURLTileLayer Initialization and Usage Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSURLTileLayer?hl=he Demonstrates how to initialize and use GMSURLTileLayer, including setting a custom user agent and map. ```APIDOC ## GMSURLTileLayer `GMSURLTileProvider` fetches tiles based on the URLs returned from a `GMSTileURLConstructor`. For example: ```objectivec GMSTileURLConstructor constructor = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) { NSString *URLStr = [NSString stringWithFormat:@"https://example.com/%d/%d/%d.png", x, y, zoom]; return [NSURL URLWithString:URLStr]; }; GMSTileLayer *layer = [GMSURLTileLayer tileLayerWithURLConstructor:constructor]; layer.userAgent = @"SDK user agent"; layer.map = map; ``` `GMSURLTileProvider` may not be subclassed and should only be created via its convenience constructor. ### +tileLayerWithURLConstructor: Convenience constructor. `constructor` must be non-nil. #### Declaration Objective-C ```objectivec + (nonnull instancetype)tileLayerWithURLConstructor: (nonnull GMSTileURLConstructor)constructor; ``` ### userAgent Specify the user agent to describe your application. If this is nil (the default), the default iOS user agent is used for HTTP requests. #### Declaration Objective-C ```objectivec @property (nonatomic, copy, nullable) NSString *userAgent; ``` ``` -------------------------------- ### GMSMapViewDelegate - mapViewDidStartTileRendering: Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate.html?hl=zh-cn Called when the map starts rendering tiles. ```APIDOC ## mapViewDidStartTileRendering: GMSMapViewDelegate ### Description Called when tiles have just been requested or labels have just started rendering. ### Method `optional func mapViewDidStartTileRendering(_ mapView: GMSMapView)` ### Endpoint N/A (Delegate Method) ### Parameters - **mapView** (GMSMapView) - The map view. ``` -------------------------------- ### GMSMapViewDelegate -mapViewDidStartTileRendering: Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate.html?hl=ja Called when the map starts rendering tiles. ```APIDOC ## GMSMapViewDelegate -mapViewDidStartTileRendering: ### Description Called when tiles have just been requested or labels have just started rendering. ### Method `optional func mapViewDidStartTileRendering(_ mapView: GMSMapView)` ### Endpoint N/A (Delegate Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### GMSURLTileLayer Initialization and Usage Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSURLTileLayer.html?hl=zh-cn Demonstrates how to initialize and use GMSURLTileLayer, including setting a custom user agent. ```APIDOC ## GMSURLTileLayer `GMSURLTileProvider` fetches tiles based on the URLs returned from a `GMSTileURLConstructor`. ### +tileLayerWithURLConstructor: Convenience constructor. `constructor` must be non-nil. #### Declaration Swift ```swift convenience init(urlConstructor constructor: @escaping GMSTileURLConstructor) ``` Objective-C ```objc + (nonnull instancetype)tileLayerWithURLConstructor: (nonnull GMSTileURLConstructor)constructor; ``` ### userAgent Specify the user agent to describe your application. If this is nil (the default), the default iOS user agent is used for HTTP requests. #### Declaration Swift ```swift var userAgent: String? { get set } ``` Objective-C ```objc @property (nonatomic, copy, nullable) NSString *userAgent; ``` ### Example Usage ```objc GMSTileURLConstructor constructor = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) { NSString *URLStr = [NSString stringWithFormat:@"https://example.com/%d/%d/%d.png", x, y, zoom]; return [NSURL URLWithString:URLStr]; }; GMSTileLayer *layer = [GMSURLTileLayer tileLayerWithURLConstructor:constructor]; layer.userAgent = @"SDK user agent"; layer.map = map; ``` `GMSURLTileProvider` may not be subclassed and should only be created via its convenience constructor. ``` -------------------------------- ### GMSMapViewDelegate -mapViewDidStartTileRendering: Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate?hl=fa Called when the map starts rendering tiles. ```APIDOC ## GMSMapViewDelegate -mapViewDidStartTileRendering: ### Description Called when tiles have just been requested or labels have just started rendering. ### Method `optional func mapViewDidStartTileRendering(_ mapView: GMSMapView)` ### Endpoint N/A (Delegate Method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response N/A #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### GMSServices Configuration Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices.html?hl=es Methods for initializing the SDK with an API key, setting options, and enabling crash reporting. ```APIDOC ## +provideAPIKey: ### Description Provides your API key to the Google Maps SDK for iOS. This must be called exactly once before any iOS Maps SDK object is initialized. ### Method Class Method ### Parameters #### Request Body - **APIKey** (String) - Required - The API key generated via the Google Cloud Platform Console. ### Response #### Success Response (200) - **Result** (Bool) - Returns YES if the APIKey was successfully provided. --- ## +provideAPIOptions: ### Description Provides API options to the Google Maps SDK for iOS. Must be called exactly once before any iOS Maps SDK object is initialized. ### Method Class Method ### Parameters #### Request Body - **APIOptions** (Array) - Required - An array containing an NSString for each option. ### Response #### Success Response (200) - **Result** (Bool) - Returns YES if all the APIOptions were successfully provided. --- ## +setAbnormalTerminationReportingEnabled: ### Description Enables or disables reporting of abnormal SDK terminations. Must be set from the main thread before the services instance is initialized. ### Method Class Method ### Parameters #### Request Body - **enabled** (Bool) - Required - YES to enable reporting, NO to disable. ``` -------------------------------- ### GMSMapViewDelegate - mapViewDidStartTileRendering Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate.html?hl=pt-br Called when the map starts rendering tiles. ```APIDOC ## mapViewDidStartTileRendering GMSMapViewDelegate ### Description Called when tiles have just been requested or labels have just started rendering. ### Method `optional func mapViewDidStartTileRendering(_ mapView: GMSMapView)` ### Endpoint N/A (Delegate Method) ### Parameters - **mapView** (GMSMapView) - The map view. ``` -------------------------------- ### Initialize GMSPanoramaService Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSPanoramaService.html?hl=es Instantiate the service to begin requesting panorama metadata. ```Objective-C @interface GMSPanoramaService : NSObject ``` ```Objective-C [[GMSPanoramaService alloc] init] ``` -------------------------------- ### GMSServices Initialization and Configuration Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices.html?hl=fr Methods for providing API credentials and configuring global SDK settings before initialization. ```APIDOC ## +provideAPIKey: ### Description Provides your API key to the Google Maps SDK for iOS. This must be called exactly once before any iOS Maps SDK object is initialized. ### Method Class Method ### Parameters #### Request Body - **APIKey** (String) - Required - The API key generated via the Google Cloud Platform Console. ### Response #### Success Response (200) - **Result** (Bool) - Returns YES if the APIKey was successfully provided. --- ## +provideAPIOptions: ### Description Provides global API options to the Google Maps SDK for iOS. Must be called exactly once before any SDK object is initialized. ### Method Class Method ### Parameters #### Request Body - **APIOptions** (Array) - Required - An array containing an NSString for each option. ### Response #### Success Response (200) - **Result** (Bool) - Returns YES if all the APIOptions were successfully provided. ``` -------------------------------- ### GMSMapViewDelegate - mapViewDidStartTileRendering Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate?hl=es-419 Called when the map starts rendering tiles. ```APIDOC ## mapViewDidStartTileRendering(_:) GMSMapViewDelegate ### Description Called when tiles have just been requested or labels have just started rendering. ### Method `optional func mapViewDidStartTileRendering(_ mapView: GMSMapView)` ### Endpoint N/A (Delegate Method) ### Parameters - **mapView** (GMSMapView) - The map view. ``` -------------------------------- ### GMSURLTileLayer Initialization and Configuration Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSURLTileLayer?hl=bn This snippet demonstrates how to initialize and configure a `GMSURLTileLayer`. ```APIDOC ## GMSURLTileLayer `GMSURLTileProvider` fetches tiles based on the URLs returned from a `GMSTileURLConstructor`. For example: ```objectivec GMSTileURLConstructor constructor = ^(NSUInteger x, NSUInteger y, NSUInteger zoom) { NSString *URLStr = [NSString stringWithFormat:@"https://example.com/%d/%d/%d.png", x, y, zoom]; return [NSURL URLWithString:URLStr]; }; GMSURLTileLayer *layer = [GMSURLTileLayer tileLayerWithURLConstructor:constructor]; layer.userAgent = @"SDK user agent"; layer.map = map; ``` `GMSURLTileProvider` may not be subclassed and should only be created via its convenience constructor. ### +tileLayerWithURLConstructor: Convenience constructor. `constructor` must be non-nil. #### Declaration Swift ```swift convenience init(urlConstructor constructor: @escaping GMSTileURLConstructor) ``` Objective-C ```objectivec + (nonnull instancetype)tileLayerWithURLConstructor: (nonnull GMSTileURLConstructor)constructor; ``` ### userAgent Specify the user agent to describe your application. If this is nil (the default), the default iOS user agent is used for HTTP requests. #### Declaration Swift ```swift var userAgent: String? { get set } ``` Objective-C ```objectivec @property (nonatomic, copy, nullable) NSString *userAgent; ``` ``` -------------------------------- ### Get encoded path string Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSPath.html?hl=de Returns the path as an encoded string. ```Swift func encodedPath() -> String ``` ```Objective-C - (nonnull NSString *)encodedPath; ``` -------------------------------- ### Initialize GMSPanoramaService Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSPanoramaService.html Instantiate GMSPanoramaService to begin requesting panorama metadata. ```Objective-C [[GMSPanoramaService alloc] init] ``` -------------------------------- ### Settings Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=zh-tw Gets the GMSUISettings object, which controls user interface settings for the map. ```APIDOC ## settings ### Description Gets the `GMSUISettings` object, which controls user interface settings for the map. ### Method GET ### Endpoint N/A (Property) ### Parameters None ### Request Example ```swift let mapSettings = mapView.settings mapSettings.zoomGestures = false ``` ### Response #### Success Response (200) - **settings** (GMSUISettings) - The GMSUISettings object for configuring map interactions. ``` -------------------------------- ### GMSServices Configuration and Initialization Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices.html?hl=id Methods for providing API credentials and configuring global SDK settings before initialization. ```APIDOC ## +provideAPIKey: ### Description Provides your API key to the Google Maps SDK for iOS. This must be called exactly once before any iOS Maps SDK object is initialized. ### Method Class Method ### Parameters #### Request Body - **APIKey** (String) - Required - The API key generated via the Google Cloud Platform Console. ### Response #### Success Response (200) - **Result** (Bool) - Returns YES if the APIKey was successfully provided. ## +provideAPIOptions: ### Description Provides global API options to the Google Maps SDK for iOS. Must be called exactly once before any SDK object is initialized. ### Method Class Method ### Parameters #### Request Body - **APIOptions** (Array) - Required - An array containing an NSString for each option. ### Response #### Success Response (200) - **Result** (Bool) - Returns YES if all the APIOptions were successfully provided. ## +setAbnormalTerminationReportingEnabled: ### Description Enables or disables reporting of abnormal SDK terminations. Must be set from the main thread before the services instance is initialized. ### Method Class Method ### Parameters #### Request Body - **enabled** (Bool) - Required - Set to YES to enable reporting (default is YES). ``` -------------------------------- ### Settings Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=fa Gets the GMSUISettings object, which controls user interface settings for the map. ```APIDOC ## settings ### Description Gets the `GMSUISettings` object, which controls user interface settings for the map. ### Method GET ### Endpoint N/A (Property of GMSMapView) ### Parameters N/A ### Request Example N/A ### Response #### Success Response (200) - **settings** (GMSUISettings) - The GMSUISettings object for configuring map UI interactions. ``` -------------------------------- ### GMSServices Configuration and Initialization Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices.html?hl=ja Methods for providing API keys, options, and configuring SDK behavior. ```APIDOC ## +provideAPIKey: ### Description Provides your API key to the Google Maps SDK for iOS. This must be called exactly once before any iOS Maps SDK object is initialized. ### Method Class Method ### Parameters #### Request Body - **APIKey** (String) - Required - The API key generated via the Google Cloud Platform Console. ### Response #### Success Response (200) - **result** (Bool) - Returns YES if the APIKey was successfully provided. --- ## +provideAPIOptions: ### Description Provides API options to the Google Maps SDK for iOS. Must be called exactly once before any iOS Maps SDK object is initialized. ### Method Class Method ### Parameters #### Request Body - **APIOptions** (Array) - Required - An array containing an NSString for each option. ### Response #### Success Response (200) - **result** (Bool) - Returns YES if all the APIOptions were successfully provided. --- ## +setAbnormalTerminationReportingEnabled: ### Description Enables or disables reporting of abnormal SDK terminations. Must be set from the main thread before the services instance is initialized. ### Method Class Method ### Parameters #### Request Body - **enabled** (Bool) - Required - YES to enable reporting, NO to disable. ``` -------------------------------- ### Settings Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView.html?hl=ko Gets the GMSUISettings object, which controls user interface settings for the map. ```APIDOC ## settings ### Description Gets the GMSUISettings object, which controls user interface settings for the map. ### Method GET ### Endpoint N/A (Property) ### Parameters N/A ### Response #### Success Response (200) - **settings** (GMSUISettings) - The GMSUISettings object for controlling map UI interactions. ``` -------------------------------- ### GMSMapView Initialization Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView.html Methods for initializing a GMSMapView instance. ```APIDOC ### Initialization Methods #### -init Initializes a new instance of `GMSMapView` with default settings. #### -initWithOptions: Initializes a new instance of `GMSMapView` with specified options. #### -initWithFrame: Initializes a new instance of `GMSMapView` with a specified frame. #### -initWithCoder: Initializes a new instance of `GMSMapView` from a decoder. #### +mapWithFrame:camera: Creates and returns a `GMSMapView` with the specified frame and camera position. #### +mapWithFrame:mapID:camera: Creates and returns a `GMSMapView` with the specified frame, map ID, and camera position. #### -initWithFrame:camera: Initializes a new instance of `GMSMapView` with the specified frame and camera position. #### -initWithFrame:mapID:camera: Initializes a new instance of `GMSMapView` with the specified frame, map ID, and camera position. ``` -------------------------------- ### Settings Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView.html?hl=id Gets the GMSUISettings object, which controls user interface settings for the map. ```APIDOC ## settings ### Description Gets the `GMSUISettings` object, which controls user interface settings for the map. ### Method GET ### Endpoint N/A (Property of GMSMapView) ### Parameters None ### Request Example None ### Response #### Success Response (200) - **settings** (GMSUISettings) - The GMSUISettings object for configuring map interactions. #### Response Example ```swift let uiSettings = mapView.settings // Example: Disable zoom controls uiSettings.zoomGestures = false ``` ``` -------------------------------- ### Settings Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView.html?hl=de Gets the GMSUISettings object, which controls user interface settings for the map. ```APIDOC ## settings ### Description Gets the `GMSUISettings` object, which controls user interface settings for the map. ### Declaration Swift ```swift var settings: GMSUISettings { get } ``` Objective-C ```objc @property (nonatomic, readonly) GMSUISettings *_Nonnull settings; ``` ``` -------------------------------- ### Initialize panorama with source Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSPanoramaView.html?hl=es Creates a GMSPanoramaView instance with a specified GMSPanoramaSource. This API is experimental. ```Swift class func panorama(withFrame frame: CGRect, nearCoordinate coordinate: CLLocationCoordinate2D, source: GMSPanoramaSource) -> Self ``` ```Objective-C + (nonnull instancetype)panoramaWithFrame:(CGRect)frame nearCoordinate:(CLLocationCoordinate2D)coordinate source:(GMSPanoramaSource)source; ``` -------------------------------- ### Settings Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=es-419 Gets the GMSUISettings object, which controls user interface settings for the map. ```APIDOC ## settings ### Description Gets the `GMSUISettings` object, which controls user interface settings for the map. ### Declaration Swift ``` var settings: GMSUISettings { get } ``` Objective-C ``` @property (nonatomic, readonly) GMSUISettings *_Nonnull settings; ``` ``` -------------------------------- ### Initialize GMSMapView with frame and camera (Deprecated) Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView.html?hl=zh-cn Deprecated initializer. Use init or initWithOptions: instead. ```Objective-C - (instancetype)initWithFrame:(CGRect)frame __GMS_AVAILABLE_BUT_DEPRECATED_MSG("Use -init or -initWithOptions: instead."); ``` -------------------------------- ### Handle start of rendering Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSPanoramaViewDelegate?hl=ar Triggered when panorama tiles are requested and loading begins. ```Swift optional func panoramaViewDidStartRendering(_ panoramaView: GMSPanoramaView) ``` ```Objective-C - (void)panoramaViewDidStartRendering:(nonnull GMSPanoramaView *)panoramaView; ``` -------------------------------- ### Initialize Map View and Camera Source: https://developers.google.com/maps/documentation/ios-sdk/examples/draw-polygons?hl=ru Sets up the GMSMapView with a specified camera position and assigns the view controller as the map view's delegate. ```objc #import "GoogleMapsDemos/Samples/PolygonsViewController.h" #import @interface PolygonsViewController () @property(nonatomic) GMSPolygon *polygonOfNewYork; @property(nonatomic) GMSPolygon *polygonOfNorthCarolina; @end @implementation PolygonsViewController - (void)viewDidLoad { [super viewDidLoad]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:39.13006 longitude:-77.508545 zoom:4]; GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; mapView.delegate = self; // needed for didTapOverlay delegate method self.view = mapView; } ``` -------------------------------- ### GMSGeometryOffset Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Functions?hl=pt-br Calculates the destination coordinate given a starting point, heading, and distance. ```APIDOC ## GMSGeometryOffset ### Description Returns the destination coordinate, when starting at `from` with initial `heading`, travelling `distance` meters along a great circle arc, on Earth. The resulting longitude is in the range [-180, 180). ### Method `func GMSGeometryOffset(_ from: CLLocationCoordinate2D, _ heading: CLLocationDirection, _ distance: CLLocationDistance) -> CLLocationCoordinate2D` (Swift) `CLLocationCoordinate2D GMSGeometryOffset(CLLocationCoordinate2D from, CLLocationDirection heading, CLLocationDistance distance)` (Objective-C) ### Parameters - **from** (CLLocationCoordinate2D) - The starting coordinate. - **heading** (CLLocationDirection) - The initial heading in degrees. - **distance** (CLLocationDistance) - The distance to travel in meters. ``` -------------------------------- ### Initialize Map and Places in Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/current-place-tutorial?hl=he Setup of GMSMapView and GMSPlacesClient within a UIViewController, including location manager configuration. ```objective-c #import "MapViewController.h" #import "PlacesViewController.h" @import CoreLocation; @import GooglePlaces; @import GoogleMaps; @interface MapViewController () @end @implementation MapViewController { CLLocationManager *locationManager; CLLocation * _Nullable currentLocation; GMSMapView *mapView; GMSPlacesClient *placesClient; float preciseLocationZoomLevel; float approximateLocationZoomLevel; // An array to hold the list of likely places. NSMutableArray *likelyPlaces; // The currently selected place. GMSPlace * _Nullable selectedPlace; } - (void)viewDidLoad { [super viewDidLoad]; preciseLocationZoomLevel = 15.0; approximateLocationZoomLevel = 15.0; // Initialize the location manager. locationManager = [[CLLocationManager alloc] init]; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager requestWhenInUseAuthorization]; locationManager.distanceFilter = 50; [locationManager startUpdatingLocation]; locationManager.delegate = self; placesClient = [GMSPlacesClient sharedClient]; // A default location to use when location permission is not granted. CLLocationCoordinate2D defaultLocation = CLLocationCoordinate2DMake(-33.869405, 151.199); // Create a map. float zoomLevel = locationManager.accuracyAuthorization == CLAccuracyAuthorizationFullAccuracy ? preciseLocationZoomLevel : approximateLocationZoomLevel; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:defaultLocation.latitude longitude:defaultLocation.longitude zoom:zoomLevel]; mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera]; mapView.settings.myLocationButton = YES; mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; mapView.myLocationEnabled = YES; // Add the map to the view, hide it until we've got a location update. [self.view addSubview:mapView]; mapView.hidden = YES; [self listLikelyPlaces]; } // Populate the array with the list of likely places. - (void) listLikelyPlaces { // Clean up from previous sessions. likelyPlaces = [NSMutableArray array]; GMSPlaceField placeFields = GMSPlaceFieldName | GMSPlaceFieldCoordinate; [placesClient findPlaceLikelihoodsFromCurrentLocationWithPlaceFields:placeFields callback:^(NSArray * _Nullable likelihoods, NSError * _Nullable error) { if (error != nil) { // TODO: Handle the error. NSLog(@"Current Place error: %@", error.localizedDescription); return; } if (likelihoods == nil) { NSLog(@"No places found."); return; } for (GMSPlaceLikelihood *likelihood in likelihoods) { GMSPlace *place = likelihood.place; [likelyPlaces addObject:place]; } }]; } // Update the map once the user has made their selection. - (void) unwindToMain:(UIStoryboardSegue *)segue { // Clear the map. [mapView clear]; // Add a marker to the map. if (selectedPlace != nil) { GMSMarker *marker = [GMSMarker markerWithPosition:selectedPlace.coordinate]; marker.title = selectedPlace.name; marker.snippet = selectedPlace.formattedAddress; marker.map = mapView; } [self listLikelyPlaces]; } // Prepare the segue. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"segueToSelect"]) { if ([segue.destinationViewController isKindOfClass:[PlacesViewController class]]) { PlacesViewController *placesViewController = (PlacesViewController *)segue.destinationViewController; placesViewController.likelyPlaces = likelyPlaces; } } } // Delegates to handle events for the location manager. #pragma mark - CLLocationManagerDelegate // Handle incoming location events. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation *location = locations.lastObject; NSLog(@"Location: %@", location); float zoomLevel = locationManager.accuracyAuthorization == CLAccuracyAuthorizationFullAccuracy ? preciseLocationZoomLevel : approximateLocationZoomLevel; ```