تقدّم هذه الصفحة دليلاً سريعًا لتصميم خريطتك، باستخدام الوضع الليلي كمثال.
نظرة عامة
باستخدام خيارات الأنماط، يمكنك تخصيص عرض أنماط خرائط Google العادية، وتغيير العرض المرئي لميزات مثل الطرق والمتنزهات والأنشطة التجارية وغيرها من المعالم المهمة. وهذا يعني أنه يمكنك التركيز على مكونات معينة من الخريطة أو جعل الخريطة تكمل نمط تطبيقك.
لا تعمل الأنماط إلا على نوع الخريطة kGMSTypeNormal.
تطبيق الأنماط على خريطتك
لتطبيق أنماط الخرائط المخصّصة على خريطة، يمكنك استدعاء GMSMapStyle(...) لإنشاء مثيل GMSMapStyle، مع تمرير عنوان URL لملف JSON محلي أو سلسلة JSON تحتوي على تعريفات الأنماط. عيِّن مثيل GMSMapStyle إلى السمة mapStyle للخريطة.
استخدام ملف JSON
The following examples show calling GMSMapStyle(...) and passing a URL for a
local file:
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)letoptions=GMSMapViewOptions()options.camera=cameraletmapView=GMSMapView(options:options)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];GMSMapViewOptions*options=[[GMSMapViewOptionsalloc]init];options.camera=camera;GMSMapView*mapView=[[GMSMapViewalloc]initWithOptions:options];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)letoptions=GMSMapViewOptions()options.camera=cameraletmapView=GMSMapView(options:options)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];GMSMapViewOptions*options=[[GMSMapViewOptionsalloc]init];options.camera=camera;GMSMapView*mapView=[[GMSMapViewalloc]initWithOptions:options];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.
استخدِم
أداة تصميم الخرائط في "منصة خرائط Google"
كطريقة سريعة لإنشاء عنصر تصميم JSON. تتيح حزمة تطوير البرامج بالاستناد إلى بيانات "خرائط Google" للتطبيقات المتوافقة مع iOS استخدام تعريفات الأنماط نفسها التي تتيحها Maps JavaScript API.
عيّنات التعليمات البرمجية الكاملة
يتضمّن مستودع ApiDemos على GitHub نماذج توضّح كيفية استخدام الأنماط.
تاريخ التعديل الأخير: 2026-10-16 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2026-10-16 (حسب التوقيت العالمي المتفَّق عليه)"],[],["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"]]