Sınırlar için veriye dayalı stil kullanmak istiyorsanız bir harita kimliği oluşturmanız gerekir. Ardından yeni bir harita stili oluşturmanız, gerekli sınır özellik katmanlarını seçmeniz ve stili harita kimliğinizle ilişkilendirmeniz gerekir.
Harita kimliği oluşturma
mapID, Google Harita'nın tek bir örneğini temsil eden benzersiz bir tanımlayıcıdır. Google Cloud Console'da istediğiniz zaman harita kimlikleri oluşturabilir ve harita kimliğiyle ilişkili bir stili güncelleyebilirsiniz.
Yeni harita stili oluşturma
Yeni bir harita stili oluşturmak için Harita stillerini yönetme bölümündeki talimatları uygulayarak stili oluşturun. İşlem tamamlandıktan sonra stili yeni oluşturulan harita kimliğiyle ilişkilendirin.
harita
kimliğine bağlandığında etkinleştirilen katmanlar koyu harita stilinde de kullanılabilir.
Özellik katmanlarını seçin
Google Cloud Console'da hangi özellik katmanlarının görüntüleneceğini seçebilirsiniz. Bu ayar, haritada hangi tür sınırların görüneceğini belirler (ör. yerleşim yerleri, eyaletler vb.).
Katman eklemek veya kaldırmak için Özellik katmanları açılır listesini tıklayın.
Değişikliklerinizi kaydetmek ve haritalarınızda kullanılabilir hale getirmek için Kaydet'i tıklayın.
Harita başlatma kodunuzu güncelleme
Bu adımda, bir veya daha fazla özellik katmanı etkinleştirilmiş bir stilin harita kimliğiyle ilişkilendirilmesi gerekir. Harita kimliğinizin Cloud Console'da doğru şekilde ayarlandığını doğrulamak için Harita Yönetimi bölümünde nasıl yapılandırıldığını inceleyin.
Swift
// A map ID using a style with one or more feature layers enabledletmapID=GMSMapID(identifier:"YOUR_MAP_ID")letmapView=GMSMapView(frame:.zero,mapID:mapID,camera:GMSCameraPosition(latitude:40,longitude:-80,zoom:7))
Objective-C
// A map ID using a style with one or more feature layers enabledGMSMapID*mapID=[GMSMapIDmapIDWithIdentifier:@"MAP_ID"];GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZeromapID:mapIDcamera:[GMSCameraPositioncameraWithLatitude:40longitude:-80zoom:7]];
Haritaya özellik katmanları ekleme
Haritanızdaki bir özellik katmanına referans almak için harita başlatıldığında mapView.featureLayer(of:) işlevini çağırın:
Sınırlarda veriye dayalı stil oluşturma için Google Cloud Console'da etkinleştirilen ve bir harita kimliğiyle ilişkilendirilen özellikler gerekir. Harita kimlikleri değişebileceğinden, belirli bir özelliğin (ör. veriye dayalı stil) kullanılıp kullanılamadığını doğrulamak için mapView.mapCapabilities işlevini GMSMapView üzerinde çağırabilirsiniz.
Ayrıca GMSViewDelegate adresine abone olarak harita özelliklerindeki değişiklikleri de tespit edebilirsiniz. Bu örnekte, veri odaklı stil oluşturma koşullarını kontrol etmek için protokolün nasıl kullanılacağı gösterilmektedir.
Swift
classSampleViewController:UIViewController{privatelazyvarmapView:GMSMapView=GMSMapView(frame:.zero,mapID:GMSMapID(identifier:"YOUR_MAP_ID"),camera:GMSCameraPosition(latitude:40,longitude:-80,zoom:7))overridefuncloadView(){self.view=mapViewmapView.delegate=self}}extensionSampleViewController:GMSMapViewDelegate{funcmapView(_mapView:GMSMapView,didChangemapCapabilities:GMSMapCapabilityFlags){if(!mapCapabilities.contains(.dataDrivenStyling)){// Data-driven styling is *not* available, add a fallback.// Existing feature layers are also unavailable.}}}
Objective-C
@interfaceSampleViewController: UIViewController<GMSMapViewDelegate>
@end@implementationSampleViewController-(void)loadView{GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZeromapID:[GMSMapIDmapIDWithIdentifier:@"MAP_ID"]camera:[GMSCameraPositioncameraWithLatitude:40longitude:-80zoom:7]];mapView.delegete=self;self.view=mapView;}-(void)mapView:(GMSMapView*)mapViewdidChangeMapCapabilities:(GMSMapCapabilityFlags)mapCapabilities{if(!(mapCapabilities&GMSMapCapabilityFlagsDataDrivenStyling)){// Data-driven styling is *not* available, add a fallback.// Existing feature layers are also unavailable.}}@end
[null,null,["Son güncelleme tarihi: 2025-08-31 UTC."],[[["\u003cp\u003eData-driven styling for boundaries requires creating a map ID and associating it with a custom map style that includes selected feature layers.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage feature layers, such as localities and states, in the Google Cloud console to control which boundaries are displayed.\u003c/p\u003e\n"],["\u003cp\u003eUpdate your map initialization code to use the map ID, ensuring data-driven styling is enabled for the map.\u003c/p\u003e\n"],["\u003cp\u003eUtilize \u003ccode\u003emapView.featureLayer(of:)\u003c/code\u003e to access specific feature layers on your map for further styling or interaction.\u003c/p\u003e\n"],["\u003cp\u003eVerify map capabilities, including data-driven styling, using \u003ccode\u003emapView.mapCapabilities\u003c/code\u003e or by subscribing to \u003ccode\u003eGMSViewDelegate\u003c/code\u003e to detect changes and implement fallbacks if needed.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-boundaries/start \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-boundaries/start \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-boundaries/start \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nTo use data-driven styling for boundaries you must create a map ID. Next, you\nmust create a new map style, select the needed boundary feature layers, and\nassociate the style with your map ID.\n\nCreate a map ID\n\nA [mapID](/maps/documentation/get-map-id) is a unique identifier that represents\na single instance of a Google Map. You can create map IDs and update a style\nassociated with a map ID at any time in the Google Cloud console.\n\nCreate a new map style\n\nTo create a new map style, follow the instructions in [Manage map\nstyles](/maps/documentation/ios-sdk/cloud-customization/map-styles) to create\nthe style. Once complete associate the style with the newly created map ID.\n| **Experimental:** This feature can only be set for light map styles. When you link a light map style that has this feature enabled to a [map\n| ID](../map-ids/mapid-over), the enabled layers are also available for the dark map style.\n\nSelect feature layers\n\nIn the Google Cloud console you can select which feature layers to display. This\ndetermines which kinds of boundaries appear on the map (for example localities,\nstates, and so on).\n| **Important:** For optimal performance, only select the layers you need.\n\nManage feature layers\n\n1. In the Google Cloud console, [go to the Map Styles\n page](https://console.cloud.google.com/project/_/google/maps-apis/studio/styles)\n\n2. Select a project if prompted.\n\n3. Select a map style.\n\n4. Click the **Feature layers** drop-down to add or remove layers.\n\n5. Click **Save** to save your changes and make them available to your maps.\n\nUpdate your map initialization code\n\nThis step requires a map ID be associated with a style with one or more feature\nlayers enabled. To verify your map ID is set up correctly in\nCloud console, review how it is configured under [Maps\nManagement](https://console.cloud.google.com/google/maps-apis/studio/maps). \n\nSwift \n\n```swift\n// A map ID using a style with one or more feature layers enabled\n\nlet mapID = GMSMapID(identifier: \"YOUR_MAP_ID\")\nlet mapView = GMSMapView(frame: .zero, mapID: mapID, camera: GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7))\n```\n\nObjective-C \n\n```objective-c\n// A map ID using a style with one or more feature layers enabled\n\nGMSMapID *mapID = [GMSMapID mapIDWithIdentifier:@\"MAP_ID\"];\nGMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:mapID camera:[GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]];\n```\n| **Important:** For testing, you can skip the step of creating and configuring a [map\n| ID](/maps/documentation/get-map-id), by using mapId: [`DEMO_MAP_ID`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapID) in your app code. `DEMO_MAP_ID` is intended for testing purposes only. Don't use `DEMO_MAP_ID` in a production environment.\n\nAdd feature layers to a map\n\nTo get a reference to a feature layer on your map, call\n[`mapView.featureLayer(of:)`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView#-featurelayeroffeaturetype:)\nwhen the map initializes: \n\nSwift \n\n```swift\nlet layer = mapView.featureLayer(of: .locality)\n```\n\nObjective-C \n\n```objective-c\nGMSFeatureLayer *layer = [mapView featureLayerOfFeatureType:GMSFeatureTypeLocality];\n```\n\nCheck map capabilities\n\nData-driven styling for boundaries requires capabilities which are enabled in the\nGoogle Cloud console, and associated with a map ID. Because map IDs are subject to\nchange, you can call\n[`mapView.mapCapabilities`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView#mapcapabilities)\non a [`GMSMapView`](/maps/documentation/ios-sdk/reference/objc/Classes/GMSMapView) to verify whether a certain capability (for\nexample data-driven styling) is available prior to calling it.\n\nYou can also detect changes in map capabilities by subscribing to\n[`GMSViewDelegate`](/maps/documentation/ios-sdk/reference/objc/Protocols/GMSMapViewDelegate). This example shows how to use the\nprotocol to check for data-driven styling requirements. \n\nSwift \n\n```swift\nclass SampleViewController: UIViewController {\n\n private lazy var mapView: GMSMapView = GMSMapView(frame: .zero, mapID: GMSMapID(identifier: \"YOUR_MAP_ID\"), camera: GMSCameraPosition(latitude: 40, longitude: -80, zoom: 7))\n\n override func loadView() {\n self.view = mapView\n mapView.delegate = self\n }\n}\n\nextension SampleViewController: GMSMapViewDelegate {\n func mapView(_ mapView: GMSMapView, didChange mapCapabilities: GMSMapCapabilityFlags) {\n if (!mapCapabilities.contains(.dataDrivenStyling)) {\n // Data-driven styling is *not* available, add a fallback.\n // Existing feature layers are also unavailable.\n }\n }\n}\n```\n\nObjective-C \n\n```objective-c\n@interface SampleViewController: UIViewController \u003cGMSMapViewDelegate\u003e\n@end\n\n@implementation SampleViewController\n- (void)loadView {\n GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero mapID:[GMSMapID mapIDWithIdentifier:@\"MAP_ID\"] camera:[GMSCameraPosition cameraWithLatitude:40 longitude:-80 zoom:7]];\n mapView.delegete = self;\n self.view = mapView;\n}\n\n- (void)mapView:(GMSMapView *)mapView didChangeMapCapabilities:(GMSMapCapabilityFlags)mapCapabilities {\n if (!(mapCapabilities & GMSMapCapabilityFlagsDataDrivenStyling)) {\n // Data-driven styling is *not* available, add a fallback.\n // Existing feature layers are also unavailable.\n }\n}\n@end\n```"]]