### GMSFeatureStyle Initialization Examples Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSFeatureStyle.html Examples of how to initialize GMSFeatureStyle objects. ```APIDOC ## Initialization Examples ### Creating a new style with specific colors and width: Objective-C: ```objectivec [GMSFeatureStyle styleWithFillColor:[UIColor redColor] strokeColor:[UIColor blackColor] strokeWidth:2.0]; ``` Swift: ```swift GMSFeatureStyle.style(withFillColor: .red, strokeColor: .black, strokeWidth: 2.0) ``` ### Initializing a new style with specific colors and width: Objective-C: ```objectivec [[GMSFeatureStyle alloc] initWithFillColor:[UIColor blueColor] strokeColor:[UIColor whiteColor] strokeWidth:1.0]; ``` Swift: ```swift init(fill: UIColor?, stroke: UIColor?, strokeWidth: CGFloat) ``` ### Initializing a default style: Objective-C: ```objectivec [[GMSFeatureStyle alloc] init]; ``` Swift: ```swift init() ``` ``` -------------------------------- ### Install SDK using Pod Install Source: https://developers.google.com/maps/documentation/ios-sdk/config Run this command in the terminal from your project directory to install the APIs and their dependencies specified in the Podfile. ```bash pod install ``` -------------------------------- ### Example: Creating and configuring GMSURLTileLayer Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSURLTileLayer?hl=he This example demonstrates how to create a GMSTileURLConstructor to generate tile URLs and then initialize a GMSURLTileLayer with it. It also shows how to set a custom user agent and assign 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=pl Example of creating and configuring a GMSURLTileLayer using a URL constructor. This class should only be created via its convenience constructor. ```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/interface_g_m_s_services Example of creating a GMSURLTileLayer to fetch tiles based on URLs. Ensure the constructor returns valid URLs and set a user agent if necessary. ```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 Usage Example Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes Example demonstrating how to use GMSURLTileLayer to fetch tiles based on URLs provided by a GMSTileURLConstructor. ```APIDOC ## GMSURLTileLayer ### Description `GMSURLTileProvider` fetches tiles based on the URLs returned from a `GMSTileURLConstructor`. For example: ``` 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. ``` -------------------------------- ### GMSURLTileLayer Example (Objective-C) Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes?hl=ru Example of creating and configuring a GMSURLTileLayer using a GMSTileURLConstructor in Objective-C. This layer fetches tiles based on provided URLs. ```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; \ ``` -------------------------------- ### Initialize a GMSMapView Source: https://developers.google.com/maps/documentation/ios-sdk/map Example demonstrating how to create and configure a GMSMapView instance centered on a specific location. ```objective-c // Create a GMSCameraPosition that tells the map to display the // coordinate -33.86, 151.20 at zoom level 6. GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:6.0]; // Create GMSMapViewOptions and set the camera. GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; options.camera = camera; // Create the GMSMapView with the options. GMSMapView *mapView = [GMSMapView mapViewWithOptions:options]; // Set the map view as the view controller's view. self.view = mapView; ``` -------------------------------- ### Initialize a GMSMapView Source: https://developers.google.com/maps/documentation/ios-sdk/map?hl=fr The following example demonstrates how to add a map centered on downtown Singapore to an application. ```objective-c GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:1.285 longitude:103.848 zoom:12]; GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init]; options.camera = camera; GMSMapView *mapView = [GMSMapView mapWithOptions:options]; self.view = mapView; ``` -------------------------------- ### Initialize Map and Location Services Source: https://developers.google.com/maps/documentation/ios-sdk/current-place-tutorial?hl=bn Setup the CLLocationManager and GMSMapView in an Objective-C view controller. ```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 SDK Version - Swift Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices?hl=de Returns the version for this release of the Google Maps SDK for iOS. For example, “1.0.0”. ```Swift class func sdkVersion() -> String ``` -------------------------------- ### Navigate and Open Sample Projects Source: https://developers.google.com/maps/documentation/ios-sdk/code-samples?hl=es Commands to navigate to the sample directories and open the Xcode project files for Swift and Objective-C. ```bash cd maps-sdk-for-ios-samples/GoogleMaps-Swift open GoogleMapsSwiftXCFrameworkDemos.xcodeproj ``` ```bash cd maps-sdk-for-ios-samples-main/GoogleMaps open GoogleMapsDemos.xcodeproj ``` -------------------------------- ### Get SDK Version - Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices?hl=de Returns the version for this release of the Google Maps SDK for iOS. For example, “1.0.0”. ```Objective-C + (nonnull NSString *)SDKVersion; ``` -------------------------------- ### Get SDK Long Version - Swift Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices?hl=de Returns the long version for this release of the Google Maps SDK for iOS. For example, “1.0.0 (102.1)”. ```Swift class func sdkLongVersion() -> String ``` -------------------------------- ### Navigate to Project Directory Source: https://developers.google.com/maps/documentation/ios-sdk/examples/basic-map Use these commands to navigate to the sample project directory in your terminal. ```shell cd maps-sdk-for-ios-samples-main/GoogleMaps open GoogleMapsDemos.xcodeproj ``` -------------------------------- ### Get SDK Long Version - Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices?hl=de Returns the long version for this release of the Google Maps SDK for iOS. For example, “1.0.0 (102.1)”. ```Objective-C + (nonnull NSString *)SDKLongVersion; ``` -------------------------------- ### Install Maps SDK via CocoaPods Source: https://developers.google.com/maps/documentation/ios-sdk/map-with-marker Install the Maps SDK using CocoaPods by running 'pod install' in the project directory. This command installs the SDK and its dependencies as defined in the Podfile. ```bash pod install ``` -------------------------------- ### Install CocoaPods Source: https://developers.google.com/maps/documentation/ios-sdk/config Install the CocoaPods dependency manager on macOS using this terminal command. Ensure you have Ruby installed. ```bash sudo gem install cocoapods ``` -------------------------------- ### Initialize API keys Source: https://developers.google.com/maps/documentation/ios-sdk/current-place-tutorial Configure the SDKs with your API key within the application launch method. ```swift GMSPlacesClient.provideAPIKey("YOUR_API_KEY") GMSServices.provideAPIKey("YOUR_API_KEY") ``` -------------------------------- ### Initialize Map and Location Services in Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/current-place-tutorial?hl=fr Setup for CLLocationManager, GMSMapView, and GMSPlacesClient within a view controller. ```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; ``` -------------------------------- ### Open Swift Demo Project in Xcode Source: https://developers.google.com/maps/documentation/ios-sdk/examples?hl=it Open the Swift demo project file in Xcode to start exploring the sample code. ```bash open GoogleMapsSwiftXCFrameworkDemos.xcodeproj ``` -------------------------------- ### Install CocoaPods Source: https://developers.google.com/maps/documentation/ios-sdk/map-with-marker Install CocoaPods using RubyGems. This command is used for managing iOS project dependencies. ```bash sudo gem install cocoapods ``` -------------------------------- ### Open Objective-C Demo Project in Xcode Source: https://developers.google.com/maps/documentation/ios-sdk/examples?hl=it Open the Objective-C demo project file in Xcode to start exploring the sample code. ```bash open GoogleMapsDemos.xcodeproj ``` -------------------------------- ### Map View Did Start Tile Rendering Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate?hl=bn Called when tiles have just been requested or labels have just started rendering. This method is part of the GMSMapViewDelegate protocol. ```swift optional func mapViewDidStartTileRendering(_ mapView: GMSMapView) ``` ```objective-c - (void)mapViewDidStartTileRendering:(nonnull GMSMapView *)mapView; ``` -------------------------------- ### GMSMapView Initializer - initWithCoder: Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=he Deprecated. Use `-init` or `-initWithOptions:` instead. ```APIDOC ## GMSMapView Initializer - initWithCoder: ### Description Deprecated. Use `-init` or `-initWithOptions:` instead. ### Declaration Swift ```swift convenience init?(coder: NSCoder) ``` Objective-C ```objc - (nullable instancetype)initWithCoder:(NSCoder *)coder __GMS_AVAILABLE_BUT_DEPRECATED_MSG("Use -init or -initWithOptions: instead."); ``` ``` -------------------------------- ### Initialize MapViewController and Core Components Source: https://developers.google.com/maps/documentation/ios-sdk/current-place-tutorial?hl=it Sets up the MapViewController, including location manager, places client, and map view. A default location is used if permission is not granted. ```swift import UIKit import GoogleMaps import GooglePlaces class MapViewController: UIViewController { var locationManager: CLLocationManager! var currentLocation: CLLocation? var mapView: GMSMapView! var placesClient: GMSPlacesClient! var preciseLocationZoomLevel: Float = 15.0 var approximateLocationZoomLevel: Float = 10.0 // An array to hold the list of likely places. var likelyPlaces: [GMSPlace] = [] // The currently selected place. var selectedPlace: GMSPlace? // Update the map once the user has made their selection. @IBAction func unwindToMain(segue: UIStoryboardSegue) { // Clear the map. mapView.clear() // Add a marker to the map. if let place = selectedPlace { let marker = GMSMarker(position: place.coordinate) marker.title = selectedPlace?.name marker.snippet = selectedPlace?.formattedAddress marker.map = mapView } listLikelyPlaces() } override func viewDidLoad() { super.viewDidLoad() // Initialize the location manager. locationManager = CLLocationManager() locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestWhenInUseAuthorization() locationManager.distanceFilter = 50 locationManager.startUpdatingLocation() locationManager.delegate = self placesClient = GMSPlacesClient.shared() // A default location to use when location permission is not granted. let defaultLocation = CLLocation(latitude: -33.869405, longitude: 151.199) // Create a map. let zoomLevel = locationManager.accuracyAuthorization == .fullAccuracy ? preciseLocationZoomLevel : approximateLocationZoomLevel let camera = GMSCameraPosition.camera(withLatitude: defaultLocation.coordinate.latitude, longitude: defaultLocation.coordinate.longitude, zoom: zoomLevel) mapView = GMSMapView.map(withFrame: view.bounds, camera: camera) mapView.settings.myLocationButton = true mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.isMyLocationEnabled = true // Add the map to the view, hide it until we've got a location update. view.addSubview(mapView) mapView.isHidden = true listLikelyPlaces() } // Populate the array with the list of likely places. func listLikelyPlaces() { // Clean up from previous sessions. likelyPlaces.removeAll() let placeFields: GMSPlaceField = [.name, .coordinate] placesClient.findPlaceLikelihoodsFromCurrentLocation(withPlaceFields: placeFields) { (placeLikelihoods, error) in guard error == nil else { // TODO: Handle the error. print("Current Place error: \(error!.localizedDescription)") return } guard let placeLikelihoods = placeLikelihoods else { print("No places found.") return } // Get likely places and add to the list. for likelihood in placeLikelihoods { let place = likelihood.place self.likelyPlaces.append(place) } } } // Prepare the segue. override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "segueToSelect" { if let nextViewController = segue.destination as? PlacesViewController { nextViewController.likelyPlaces = likelyPlaces } } } } // Delegates to handle events for the location manager. extension MapViewController: CLLocationManagerDelegate { // Handle incoming location events. func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { let location: CLLocation = locations.last! print("Location: \(location)") let zoomLevel = locationManager.accuracyAuthorization == .fullAccuracy ? preciseLocationZoomLevel : approximateLocationZoomLevel let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude, longitude: location.coordinate.longitude, zoom: zoomLevel) if mapView.isHidden { mapView.isHidden = false mapView.camera = camera } else { mapView.animate(to: camera) } listLikelyPlaces() } // Handle authorization for the location manager. func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { // Check accuracy authorization let accuracy = manager.accuracyAuthorization switch accuracy { case .fullAccuracy: print("Location accuracy is precise.") case .reducedAccuracy: print("Location accuracy is not precise.") @unknown default: fatalError() } // Handle authorization status switch status { case .restricted: print("Location access was restricted.") case .denied: print("User denied access to location.") // Display the map using the default location. mapView.isHidden = false ``` -------------------------------- ### GMSURLTileLayer Initialization and Configuration Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSURLTileLayer?hl=pl Documentation for initializing GMSURLTileLayer using a URL constructor and configuring the user agent. ```APIDOC ## +tileLayerWithURLConstructor: ### Description Convenience constructor to create a GMSURLTileLayer instance. The provided constructor must be non-nil. ### Method Class Method ### Parameters #### Path Parameters - **constructor** (GMSTileURLConstructor) - Required - A block that returns an NSURL for given x, y, and zoom levels. ### Request Example ``` 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]; ``` ## userAgent ### Description Property to specify the user agent string for HTTP requests. If set to nil, the default iOS user agent is used. ### Method Property Accessor ### Parameters - **userAgent** (NSString*) - Optional - The string identifying the application. ``` -------------------------------- ### Initialize and Configure GMSMapView and Polygons (Objective-C) Source: https://developers.google.com/maps/documentation/ios-sdk/examples/draw-polygons?hl=id Sets up the GMSMapView, defines camera position, and creates two GMSPolygon objects for New York and North Carolina. Includes delegate setup for tap events. ```objectivec #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]; ``` -------------------------------- ### Polygon Data Styling Example Source: https://developers.google.com/maps/documentation/ios-sdk/dds-datasets/style-data-features This example demonstrates styling polygon geometry based on data features. The provided GeoJSON excerpt shows a representative feature entry for parks in New York City. ```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 ] ] ] ] } } ``` -------------------------------- ### GMSMapView Initializer - init() Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=he Initializes a new GMSMapView instance with default options and a frame of `CGRectZero`. ```APIDOC ## GMSMapView Initializer - init() ### Description Initializes with `CGRectZero` and default options. ### Declaration Swift ```swift convenience init() ``` Objective-C ```objc - (nonnull instancetype)init; ``` ``` -------------------------------- ### GMSFeatureLayer Styling Example Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSFeatureLayer.html Example demonstrating how to apply conditional styling to features within a GMSFeatureLayer based on a set of selected place IDs. It shows updating the style by modifying the selected IDs and re-assigning the style block. ```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 } ``` -------------------------------- ### Clone Sample App Repository Source: https://developers.google.com/maps/documentation/ios-sdk/examples/draw-polylines Clone the sample app repository from GitHub to your local machine. ```bash git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.git ``` -------------------------------- ### mapViewDidStartTileRendering: Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate.html?hl=es Called when the map starts rendering tiles. ```APIDOC ## mapViewDidStartTileRendering: ### Description Called when tiles have just been requested or labels have just started rendering. ### Method `optional func mapViewDidStartTileRendering(_ mapView: GMSMapView)` (Swift) `- (void)mapViewDidStartTileRendering:(nonnull GMSMapView *)mapView;` (Objective-C) ``` -------------------------------- ### Objective-C: Navigate to Google Maps SDK Sample App Directory Source: https://developers.google.com/maps/documentation/ios-sdk/examples/enable-my-location Command to change the current directory to the Objective-C sample app folder within the cloned repository. ```shell cd maps-sdk-for-ios-samples-main/GoogleMaps ``` -------------------------------- ### GMSFeatureStyle Copying Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSFeatureStyle.html Examples of creating copies of GMSFeatureStyle objects. ```APIDOC ## Copying Examples Assuming you have a `GMSFeatureStyle` object named `featureStyle`: ### Creating a copy: Objective-C: ```objectivec GMSFeatureStyle *copiedStyle = [featureStyle copy]; ``` Swift: ```swift let copiedStyle = featureStyle.copy() as! FeatureStyle ``` ### Creating a mutable copy: Objective-C: ```objectivec GMSMutableFeatureStyle *mutableCopy = [featureStyle mutableCopy]; ``` Swift: ```swift let mutableCopy = featureStyle.mutableCopy() as! MutableFeatureStyle ``` ``` -------------------------------- ### GMSMapStyle Initialization Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapStyle?hl=pt-br Methods for creating 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. ### 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. ### Request Example "{\"stylers\": [{\"visibility\": \"off\"}]}" ## +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. ### Parameters - **fileURL** (NSURL) - Required - The URL of the JSON file containing the style definition. - **error** (NSError**) - Optional - A pointer to an error object to be populated if the style is invalid or the file is inaccessible. ``` -------------------------------- ### 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 ## 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 ``` -------------------------------- ### mapViewDidStartTileRendering: Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate?hl=bn Called when tiles have just been requested or labels have just started rendering. ```APIDOC ## mapViewDidStartTileRendering: ### Description Called when tiles have just been requested or labels have just started rendering. ### Parameters #### Path Parameters - **mapView** (GMSMapView) - Required - The map view that started rendering. ``` -------------------------------- ### GMSURLTileLayer Initialization and Usage Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSURLTileLayer?hl=bn 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`. For example: ```swift let constructor: GMSTileURLConstructor = { return URL(string: String(format: "https://example.com/%d/%d/%d.png", $0, $1, $2)) } let layer = GMSURLTileLayer(urlConstructor: constructor) layer.userAgent = "SDK user agent" layer.map = map ``` `GMSURLTileProvider` may not be subclassed and should only be created via its convenience constructor. ``` -------------------------------- ### Get Path Count Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSPath.html Retrieves the number of coordinates in the path. ```Swift func count() -> UInt ``` ```Objective-C - (NSUInteger)count; ``` -------------------------------- ### Swift: Navigate to Google Maps SDK Sample App Directory Source: https://developers.google.com/maps/documentation/ios-sdk/examples/enable-my-location Command to change the current directory to the Swift sample app folder within the cloned repository. ```shell cd maps-sdk-for-ios-samples/GoogleMaps-Swift ``` -------------------------------- ### Access opacity property Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMarkerLayer.html Get or set the opacity of the marker. ```Swift var opacity: Float { get set } ``` ```Objective-C @property float opacity; ``` -------------------------------- ### GMSServices Configuration Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSServices?hl=es Methods for initializing the SDK, providing API keys, and configuring global settings. ```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. ### Parameters - **APIKey** (String) - Required - The API key generated via the Google Cloud Platform Console. ### Response - **Return Value** (Bool) - 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. ### Parameters - **APIOptions** (Array) - Required - An array containing an NSString for each option. ### Response - **Return Value** (Bool) - YES if all the APIOptions were successfully provided. ## +setAbnormalTerminationReportingEnabled: ### Description Enables or disables reporting of abnormal SDK terminations. Must be updated before the services instance is initialized. ### Parameters - **enabled** (Bool) - Required - Set to YES to enable reporting (default is YES). ``` -------------------------------- ### Access rotation property Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMarkerLayer.html Get or set the rotation of the marker. ```Swift var rotation: CLLocationDegrees { get set } ``` ```Objective-C @property (nonatomic) CLLocationDegrees rotation; ``` -------------------------------- ### Navigate to Project Directory Source: https://developers.google.com/maps/documentation/ios-sdk/config Change to the directory containing your Podfile using the terminal. Replace '' with the actual path. ```bash cd ``` -------------------------------- ### GMSFeatureStyle Property Access Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSFeatureStyle.html Examples of accessing properties of a GMSFeatureStyle object. ```APIDOC ## Property Access Examples Assuming you have a `GMSFeatureStyle` object named `featureStyle`: ### Accessing fillColor: Objective-C: ```objectivec UIColor *fill = featureStyle.fillColor; ``` Swift: ```swift let fill = featureStyle.fillColor ``` ### Accessing strokeColor: Objective-C: ```objectivec UIColor *stroke = featureStyle.strokeColor; ``` Swift: ```swift let stroke = featureStyle.strokeColor ``` ### Accessing strokeWidth: Objective-C: ```objectivec CGFloat width = featureStyle.strokeWidth; ``` Swift: ```swift let width = featureStyle.strokeWidth ``` ### Accessing pointRadius: Objective-C: ```objectivec CGFloat radius = featureStyle.pointRadius; ``` Swift: ```swift let radius = featureStyle.pointRadius ``` ``` -------------------------------- ### Create and Interact with Polygons in Objective-C Source: https://developers.google.com/maps/documentation/ios-sdk/examples/draw-polygons?hl=he This example shows how to initialize a GMSMapView, define polygon paths, and handle tap events to change polygon fill colors. ```objective-c #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]; [path addLatitude:42.9554 longitude:-78.9313]; [path addLatitude:42.9584 longitude:-78.9656]; [path addLatitude:42.9886 longitude:-79.0219]; [path addLatitude:43.0568 longitude:-79.0027]; [path addLatitude:43.0769 longitude:-79.0727]; [path addLatitude:43.1220 longitude:-79.0713]; [path addLatitude:43.1441 longitude:-79.0302]; [path addLatitude:43.1801 longitude:-79.0576]; [path addLatitude:43.2482 longitude:-79.0604]; [path addLatitude:43.2812 longitude:-79.0837]; [path addLatitude:43.4509 longitude:-79.2004]; [path addLatitude:43.6311 longitude:-78.6909]; [path addLatitude:43.6321 longitude:-76.7958]; [path addLatitude:43.9987 longitude:-76.4978]; [path addLatitude:44.0965 longitude:-76.4388]; [path addLatitude:44.1349 longitude:-76.3536]; [path addLatitude:44.1989 longitude:-76.3124]; [path addLatitude:44.2049 longitude:-76.2437]; [path addLatitude:44.2413 longitude:-76.1655]; [path addLatitude:44.2973 longitude:-76.1353]; [path addLatitude:44.3327 longitude:-76.0474]; [path addLatitude:44.3553 longitude:-75.9856]; [path addLatitude:44.3749 longitude:-75.9196]; [path addLatitude:44.3994 longitude:-75.8730]; [path addLatitude:44.4308 longitude:-75.8221]; [path addLatitude:44.4740 longitude:-75.8098]; [path addLatitude:44.5425 longitude:-75.7288]; [path addLatitude:44.6647 longitude:-75.5585]; [path addLatitude:44.7672 longitude:-75.4088]; [path addLatitude:44.8101 longitude:-75.3442]; [path addLatitude:44.8383 longitude:-75.3058]; [path addLatitude:44.8676 longitude:-75.2399]; [path addLatitude:44.9211 longitude:-75.1204]; [path addLatitude:44.9609 longitude:-74.9995]; [path addLatitude:44.9803 longitude:-74.9899]; [path addLatitude:44.9852 longitude:-74.9103]; [path addLatitude:45.0017 longitude:-74.8856]; [path addLatitude:45.0153 longitude:-74.8306]; [path addLatitude:45.0046 longitude:-74.7633]; [path addLatitude:45.0027 longitude:-74.7070]; [path addLatitude:45.0007 longitude:-74.5642]; [path addLatitude:44.9920 longitude:-74.1467]; [path addLatitude:45.0037 longitude:-73.7306]; [path addLatitude:45.0085 longitude:-73.4203]; [path addLatitude:45.0109 longitude:-73.3430]; [path addLatitude:44.9874 longitude:-73.3547]; [path addLatitude:44.9648 longitude:-73.3379]; [path addLatitude:44.9160 longitude:-73.3396]; [path addLatitude:44.8354 longitude:-73.3739]; [path addLatitude:44.8013 longitude:-73.3324]; ``` -------------------------------- ### Handle start of rendering Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Protocols/GMSPanoramaViewDelegate?hl=ar Triggered when panorama tiles begin loading. ```Swift optional func panoramaViewDidStartRendering(_ panoramaView: GMSPanoramaView) ``` ```Objective-C - (void)panoramaViewDidStartRendering:(nonnull GMSPanoramaView *)panoramaView; ``` -------------------------------- ### Initialize GMSPanoramaService Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSPanoramaService.html Get an instance of GMSPanoramaService to request panorama metadata. ```Objective-C @implementation GMSPanoramaService : NSObject @end ``` -------------------------------- ### Access cameraTargetBounds Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=ar Property to get or set the bounds for the camera target. ```Swift var cameraTargetBounds: GMSCoordinateBounds? { get set } ``` ```Objective-C @property (nonatomic, nullable) GMSCoordinateBounds *cameraTargetBounds; ``` -------------------------------- ### GMSMapView Initializer - initWithFrame: Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=he Deprecated. Use `-init` or `-initWithOptions:` instead. ```APIDOC ## GMSMapView Initializer - initWithFrame: ### Description Deprecated. Use `-init` or `-initWithOptions:` instead. ### Declaration Swift ```swift convenience init(frame: CGRect) ``` Objective-C ```objc - (instancetype)initWithFrame:(CGRect)frame __GMS_AVAILABLE_BUT_DEPRECATED_MSG("Use -init or -initWithOptions: instead."); ``` ``` -------------------------------- ### Access cameraLongitude Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapLayer.html?hl=fr Property to get or set the longitude of the map camera. ```Swift var cameraLongitude: CLLocationDegrees { get set } ``` ```Objective-C @property(nonatomic) CLLocationDegrees cameraLongitude ``` -------------------------------- ### Access cameraLatitude Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapLayer.html?hl=fr Property to get or set the latitude of the map camera. ```Swift var cameraLatitude: CLLocationDegrees { get set } ``` ```Objective-C @property(nonatomic) CLLocationDegrees cameraLatitude ``` -------------------------------- ### GMSMapView Initialization Methods Source: https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView?hl=es-419 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 the specified options. ### -initWithFrame: Initializes a new instance of `GMSMapView` with the 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 `GMSMSMapView` 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. ```