Bu sayfada, gece modunu örnek olarak kullanarak haritanızı stilize etmeyle ilgili kısa bir kılavuz sunulmaktadır.
Genel Bakış
Stil seçenekleriyle standart Google harita stillerinin sunumunu özelleştirebilir, yollar, parklar, işletmeler ve diğer ilgi çekici yerler gibi özelliklerin görsel gösterimini değiştirebilirsiniz. Bu sayede, haritanın belirli bileşenlerini vurgulayabilir veya haritanın uygulamanızın stiline uygun olmasını sağlayabilirsiniz.
Stil yalnızca kGMSTypeNormal harita türünde çalışır.
Haritanıza stil uygulama
Özel harita stillerini bir haritaya uygulamak için GMSMapStyle(...) çağrısı yaparak bir GMSMapStyle örneği oluşturun ve yerel bir JSON dosyası için URL veya stil tanımlarını içeren bir JSON dizesi iletin. GMSMapStyle örneğini haritanın mapStyle özelliğine atayın.
JSON dosyası kullanma
Aşağıdaki örneklerde, yerel bir dosya için URL'nin çağrılması GMSMapStyle(...) ve iletilmesi gösterilmektedir:
Swift
importGoogleMapsclassMapStyling:UIViewController{// Set the status bar style to complement night-mode.overridevarpreferredStatusBarStyle:UIStatusBarStyle{return.lightContent}overridefuncloadView(){letcamera=GMSCameraPosition.camera(withLatitude:-33.86,longitude:151.20,zoom:14.0)letmapView=GMSMapView.map(withFrame:CGRect.zero,camera:camera)do{// Set the map style by passing the URL of the local file.ifletstyleURL=Bundle.main.url(forResource:"style",withExtension:"json"){mapView.mapStyle=tryGMSMapStyle(contentsOfFileURL:styleURL)}else{NSLog("Unable to find style.json")}}catch{NSLog("One or more of the map styles failed to load. \(error)")}self.view=mapView}}
Objective-C
#import "MapStyling.h"@importGoogleMaps;@interfaceMapStyling()@end@implementationMapStyling// Set the status bar style to complement night-mode.-(UIStatusBarStyle)preferredStatusBarStyle{returnUIStatusBarStyleLightContent;}-(void)loadView{GMSCameraPosition*camera=[GMSCameraPositioncameraWithLatitude:-33.86longitude:151.20zoom:12];GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZerocamera:camera];mapView.myLocationEnabled=YES;NSBundle*mainBundle=[NSBundlemainBundle];NSURL*styleUrl=[mainBundleURLForResource:@"style"withExtension:@"json"];NSError*error;// Set the map style by passing the URL for style.json.GMSMapStyle*style=[GMSMapStylestyleWithContentsOfFileURL:styleUrlerror:&error];if(!style){NSLog(@"The style definition could not be loaded: %@",error);}mapView.mapStyle=style;self.view=mapView;}@end
Stil seçeneklerini tanımlamak için projenize style.json adlı yeni bir dosya ekleyin ve gece modu stili için aşağıdaki JSON stil bildirimini yapıştırın:
Aşağıdaki örneklerde GMSMapStyle(...) çağrısı ve dize kaynağı iletme gösterilmektedir:
Swift
classMapStylingStringResource:UIViewController{letMapStyle="JSON_STYLE_GOES_HERE"// Set the status bar style to complement night-mode.overridevarpreferredStatusBarStyle:UIStatusBarStyle{return.lightContent}overridefuncloadView(){letcamera=GMSCameraPosition.camera(withLatitude:-33.86,longitude:151.20,zoom:14.0)letmapView=GMSMapView.map(withFrame:CGRect.zero,camera:camera)do{// Set the map style by passing a valid JSON string.mapView.mapStyle=tryGMSMapStyle(jsonString:MapStyle)}catch{NSLog("One or more of the map styles failed to load. \(error)")}self.view=mapView}}
Objective-C
@implementationMapStylingStringResource// Paste the JSON string to use.staticNSString*constkMapStyle=@"JSON_STYLE_GOES_HERE";// Set the status bar style to complement night-mode.-(UIStatusBarStyle)preferredStatusBarStyle{returnUIStatusBarStyleLightContent;}-(void)loadView{GMSCameraPosition*camera=[GMSCameraPositioncameraWithLatitude:-33.86longitude:151.20zoom:12];GMSMapView*mapView=[GMSMapViewmapWithFrame:CGRectZerocamera:camera];mapView.myLocationEnabled=YES;NSError*error;// Set the map style by passing a valid JSON string.GMSMapStyle*style=[GMSMapStylestyleWithJSONString:kMapStyleerror:&error];if(!style){NSLog(@"The style definition could not be loaded: %@",error);}mapView.mapStyle=style;self.view=mapView;}@end
Stil seçeneklerini tanımlamak için aşağıdaki stil dizesini kMapStyle değişkeninin değeri olarak yapıştırın:
Stil verilmiş haritalar, renklendirme ve diğer stil değişikliklerini haritaya uygulamak için iki kavram kullanır:
Seçiciler, haritada stil uygulayabileceğiniz coğrafi bileşenleri belirtir. Yollar, parklar, su kütleleri ve daha fazlası ile bunların etiketleri bu kapsamda yer alır. Seçiciler, featureType ve elementType özellikleri olarak belirtilen özellikler ve öğeler içerir.
Stil araçları, harita öğelerine uygulayabileceğiniz renk ve görünürlük özellikleridir. Görüntülenen rengi; renk tonu, renk, parlaklık ve gama değerlerinin bir kombinasyonuyla tanımlarlar.
JSON stil seçeneklerinin ayrıntılı açıklaması için stil referansına bakın.
JSON stil nesnesi oluşturmanın hızlı bir yolu olarak Maps Platform Stil Sihirbazı'nı kullanın. iOS için Haritalar SDK'sı, Maps JavaScript API ile aynı stil bildirimlerini destekler.
Tam kod örnekleri
GitHub'daki ApiDemos deposunda, stil kullanımını gösteren örnekler yer alır.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 2025-07-16 UTC."],[[["This guide provides instructions for styling Google Maps using JSON to customize the appearance of map elements."],["You can style your map using a local JSON file or a JSON string, applying it to the `mapStyle` property of the map."],["JSON style declarations consist of selectors (`featureType`, `elementType`) to target map components and stylers to define their visual properties."],["Leverage the Maps Platform Styling Wizard to easily create custom JSON styles and apply them to your maps."],["Styling is applicable only to the `kGMSTypeNormal` map type and offers flexibility in highlighting or blending map features with your application's design."]]],["To customize map appearance, apply styles to the `kGMSTypeNormal` map type. Utilize `GMSMapStyle` by passing a URL for a local JSON file or a JSON string to the `mapStyle` property. Define styles with selectors (features and elements) and stylers (color, visibility). Create a `style.json` file for night-mode styling with the provided JSON or use a JSON string directly. Consider cloud customization for uniform styling across multiple apps. The Maps Platform Styling Wizard can help generate JSON style objects. Avoid mixing cloud and hardcoded styles.\n"]]