इस पेज पर, मैप को स्टाइल करने के बारे में जानकारी दी गई है. इसमें नाइट मोड का इस्तेमाल करने का तरीका बताया गया है.
खास जानकारी
स्टाइल के विकल्पों की मदद से, Google मैप की स्टैंडर्ड स्टाइल को अपनी पसंद के मुताबिक बनाया जा सकता है. साथ ही, सड़कों, पार्कों, कारोबारों, और दिलचस्पी की अन्य जगहों जैसी सुविधाओं के विज़ुअल डिसप्ले को बदला जा सकता है. इसका मतलब है कि मैप के किसी कॉम्पोनेंट को हाइलाइट किया जा सकता है या मैप को अपने ऐप्लिकेशन की स्टाइल के हिसाब से बनाया जा सकता है.
स्टाइलिंग की सुविधा सिर्फ़ kGMSTypeNormal मैप टाइप पर काम करती है.
अपने मैप पर स्टाइल लागू करना
किसी मैप पर कस्टम मैप स्टाइल लागू करने के लिए, GMSMapStyle(...) को कॉल करके GMSMapStyle इंस्टेंस बनाएं. इसके लिए, स्टाइल की परिभाषाओं वाली JSON स्ट्रिंग या स्थानीय JSON फ़ाइल का यूआरएल पास करें. GMSMapStyle इंस्टेंस को मैप की mapStyle प्रॉपर्टी को असाइन करें.
JSON फ़ाइल का इस्तेमाल करना
यहां दिए गए उदाहरणों में, GMSMapStyle(...) को कॉल करने और किसी स्थानीय फ़ाइल के लिए यूआरएल पास करने का तरीका दिखाया गया है:
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
स्टाइल के विकल्पों को तय करने के लिए, अपने प्रोजेक्ट में style.json नाम की एक नई फ़ाइल जोड़ें. इसके बाद, नाइट मोड की स्टाइलिंग के लिए, यहां दिया गया JSON स्टाइल डिक्लेरेशन चिपकाएं:
यहां दिए गए उदाहरणों में, GMSMapStyle(...) को कॉल करने और स्ट्रिंग संसाधन पास करने का तरीका दिखाया गया है:
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
स्टाइल के विकल्प तय करने के लिए, स्टाइल स्ट्रिंग को kMapStyle वैरिएबल की वैल्यू के तौर पर चिपकाएं:
स्टाइल किए गए मैप में, मैप पर रंग और स्टाइल से जुड़े अन्य बदलाव लागू करने के लिए, दो कॉन्सेप्ट का इस्तेमाल किया जाता है:
चुनने वाले टूल, मैप पर स्टाइल किए जा सकने वाले भौगोलिक कॉम्पोनेंट तय करते हैं. इनमें सड़कें, पार्क, जलाशय वगैरह शामिल हैं. साथ ही, इनके लेबल भी शामिल हैं. इन सिलेक्टर में सुविधाएं और तत्व शामिल हैं. इन्हें featureType और elementType प्रॉपर्टी के तौर पर तय किया गया है.
स्टाइलर, रंग और दिखने की प्रॉपर्टी होती हैं. इन्हें मैप के एलिमेंट पर लागू किया जा सकता है. ये रंग, रंग, और चमक के साथ-साथ गामा वैल्यू के कॉम्बिनेशन के ज़रिए दिखाए गए रंग को तय करते हैं.
JSON स्टाइलिंग के विकल्पों के बारे में ज़्यादा जानकारी के लिए, स्टाइल रेफ़रंस देखें.
JSON स्टाइलिंग ऑब्जेक्ट जनरेट करने के लिए, Maps Platform स्टाइलिंग विज़र्ड का इस्तेमाल करें. iOS के लिए Maps SDK, Maps JavaScript API की तरह ही स्टाइल के एलान करने की सुविधा देता है.
पूरे कोड सैंपल
GitHub पर मौजूद ApiDemos रिपॉज़िटरी में ऐसे सैंपल शामिल हैं जिनसे स्टाइलिंग के इस्तेमाल के बारे में पता चलता है.
[null,null,["आखिरी बार 2025-09-12 (UTC) को अपडेट किया गया."],[],["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"],null,[]]