مخفی کردن ویژگی های نقشه با یک ظاهر طراحی
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پلتفرم را انتخاب کنید: Android iOS JavaScript علاوه بر تغییر سبک ویژگیهای روی نقشه، میتوانید آنها را به طور کامل پنهان کنید. این مثال به شما نشان می دهد که چگونه نقاط مورد علاقه تجاری (POI) و نمادهای حمل و نقل عمومی را روی نقشه خود پنهان کنید.
یک ظاهر طراحی شده فقط در نوع نقشه kGMSTypeNormal
کار می کند.
اعمال سبک ها در نقشه شما
برای اعمال سبکهای نقشه سفارشی روی نقشه، با GMSMapStyle(...)
تماس بگیرید تا یک نمونه GMSMapStyle
ایجاد کنید، یک URL برای یک فایل JSON محلی یا یک رشته JSON حاوی تعاریف سبک ارسال کنید. نمونه GMSMapStyle
را به ویژگی mapStyle
نقشه اختصاص دهید.
استفاده از فایل JSON
مثال های زیر فراخوانی GMSMapStyle(...)
و ارسال URL برای یک فایل محلی را نشان می دهد:
نمونه کد زیر فرض می کند که پروژه شما حاوی فایلی به نام style.json
است:
سویفت
import GoogleMaps
class MapStyling: UIViewController {
// Set the status bar style to complement night-mode.
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func loadView() {
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 14.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
do {
// Set the map style by passing the URL of the local file.
if let styleURL = Bundle.main.url(forResource: "style", withExtension: "json") {
mapView.mapStyle = try GMSMapStyle(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
}
}
هدف-C
#import "MapStyling.h"
@import GoogleMaps;
@interface MapStyling ()
@end
@implementation MapStyling
// Set the status bar style to complement night-mode.
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:12];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *styleUrl = [mainBundle URLForResource:@"style" withExtension:@"json"];
NSError *error;
// Set the map style by passing the URL for style.json.
GMSMapStyle *style = [GMSMapStyle styleWithContentsOfFileURL:styleUrl error:&error];
if (!style) {
NSLog(@"The style definition could not be loaded: %@", error);
}
mapView.mapStyle = style;
self.view = mapView;
}
@end
برای تعریف گزینههای سبک، یک فایل جدید به نام style.json
را به پروژه خود اضافه کنید و اعلان سبک JSON زیر را برای پنهان کردن نقاط مورد علاقه تجاری (POI) و نمادهای حملونقل عمومی جایگذاری کنید:
نمایش/پنهان کردن JSON
[
{
"featureType": "poi.business",
"elementType": "all",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "transit",
"elementType": "labels.icon",
"stylers": [
{
"visibility": "off"
}
]
}
]
استفاده از منبع رشته ای
مثالهای زیر فراخوانی GMSMapStyle()
و ارسال یک منبع رشته را نشان میدهند:
سویفت
class MapStylingStringResource: UIViewController {
let MapStyle = "JSON_STYLE_GOES_HERE"
// Set the status bar style to complement night-mode.
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func loadView() {
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 14.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
do {
// Set the map style by passing a valid JSON string.
mapView.mapStyle = try GMSMapStyle(jsonString: MapStyle)
} catch {
NSLog("One or more of the map styles failed to load. \(error)")
}
self.view = mapView
}
}
هدف-C
@implementation MapStylingStringResource
// Paste the JSON string to use.
static NSString *const kMapStyle = @"JSON_STYLE_GOES_HERE";
// Set the status bar style to complement night-mode.
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)loadView {
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
longitude:151.20
zoom:12];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView.myLocationEnabled = YES;
NSError *error;
// Set the map style by passing a valid JSON string.
GMSMapStyle *style = [GMSMapStyle styleWithJSONString:kMapStyle error:&error];
if (!style) {
NSLog(@"The style definition could not be loaded: %@", error);
}
mapView.mapStyle = style;
self.view = mapView;
}
@end
اعلان سبک زیر نقاط مورد علاقه تجاری (POI) و نمادهای حمل و نقل عمومی را پنهان می کند. رشته سبک زیر را به عنوان مقدار متغیر kMapStyle
قرار دهید:
نمایش/پنهان کردن JSON
@"["
@" {"
@" \"featureType\": \"poi.business\","
@" \"elementType\": \"all\","
@" \"stylers\": ["
@" {"
@" \"visibility\": \"off\""
@" }"
@" ]"
@" },"
@" {"
@" \"featureType\": \"transit\","
@" \"elementType\": \"labels.icon\","
@" \"stylers\": ["
@" {"
@" \"visibility\": \"off\""
@" }"
@" ]"
@" }"
@"]"
اعلان های سبک JSON
نقشه های سبک از دو مفهوم برای اعمال رنگ ها و سایر تغییرات سبک در نقشه استفاده می کنند:
- انتخابگرها اجزای جغرافیایی را مشخص میکنند که میتوانید روی نقشه استایل دهید. اینها شامل جاده ها، پارک ها، منابع آبی و موارد دیگر و همچنین برچسب های آنها می شود. انتخابگرها شامل ویژگیها و عناصر هستند که به عنوان ویژگیهای
featureType
و elementType
مشخص میشوند. - استایلرها ویژگیهای رنگ و دید هستند که میتوانید روی عناصر نقشه اعمال کنید. آنها رنگ نمایش داده شده را از طریق ترکیبی از مقادیر رنگ، رنگ و روشنایی/گاما تعریف می کنند.
برای توضیحات مفصل گزینه های سبک JSON به مرجع سبک مراجعه کنید.
از Maps Platform Styling Wizard به عنوان یک راه سریع برای تولید یک شی استایل JSON استفاده کنید. Maps SDK برای iOS از اعلانهای سبک مشابه با Maps JavaScript API پشتیبانی میکند.
نمونه کد کامل
مخزن ApiDemos در GitHub شامل نمونه هایی است که استفاده از استایل را نشان می دهد.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eLearn how to hide map features like business POIs and transit icons using the Google Maps SDK for iOS.\u003c/p\u003e\n"],["\u003cp\u003eApply custom styles by providing a local JSON file or a JSON string containing style definitions to the \u003ccode\u003emapStyle\u003c/code\u003e property of your map.\u003c/p\u003e\n"],["\u003cp\u003eUtilize the \u003ccode\u003efeatureType\u003c/code\u003e and \u003ccode\u003eelementType\u003c/code\u003e properties in your JSON to select the specific map components you want to style.\u003c/p\u003e\n"],["\u003cp\u003eControl the visibility and color of map elements through \u003ccode\u003estylers\u003c/code\u003e in your JSON style declaration.\u003c/p\u003e\n"],["\u003cp\u003eExplore the Maps Platform Styling Wizard for a user-friendly way to generate JSON styling objects for your map.\u003c/p\u003e\n"]]],["To style maps, you can hide features like business POIs and transit icons. Apply styles using `GMSMapStyle`, either with a local JSON file URL or a JSON string. Create a `style.json` file, and use selectors (features and elements) and stylers (visibility) to define map styles. Use the `mapStyle` property on the map to apply styles. Alternatively, you can define a JSON string with the same style options. You can utilize the [Maps Platform Styling Wizard](https://mapstyle.withgoogle.com) for an efficient JSON style object creation.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/hiding-features \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/hiding-features \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/json-styling-overview \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nAs well as changing the style of features on the map, you can also hide them\nentirely. This example shows you how to hide business points of interest (POIs)\nand public transit icons on your map.\n\nStyling works only on the `kGMSTypeNormal` map type.\n\nApplying styles to your map\n\nTo apply custom map styles to a map, call `GMSMapStyle(...)` to create a\n`GMSMapStyle` instance, passing in a URL for a local JSON file, or a JSON\nstring containing style definitions. Assign the `GMSMapStyle` instance to the\n`mapStyle` property of the map.\n\nUsing a JSON file\n\nThe following examples show calling `GMSMapStyle(...)` and passing a URL for a\nlocal file:\n\nThe following code sample assumes your project contains a file named\n`style.json`:\n\n\nSwift \n\n```swift\nimport GoogleMaps\n\nclass MapStyling: UIViewController {\n\n // Set the status bar style to complement night-mode.\n override var preferredStatusBarStyle: UIStatusBarStyle {\n return .lightContent\n }\n\n override func loadView() {\n let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 14.0)\n let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)\n\n do {\n // Set the map style by passing the URL of the local file.\n if let styleURL = Bundle.main.url(forResource: \"style\", withExtension: \"json\") {\n mapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)\n } else {\n NSLog(\"Unable to find style.json\")\n }\n } catch {\n NSLog(\"One or more of the map styles failed to load. \\(error)\")\n }\n\n self.view = mapView\n }\n}\n \n```\n\nObjective-C \n\n```objective-c\n#import \"MapStyling.h\"\n@import GoogleMaps;\n\n@interface MapStyling ()\n\n@end\n\n@implementation MapStyling\n\n// Set the status bar style to complement night-mode.\n- (UIStatusBarStyle)preferredStatusBarStyle {\n return UIStatusBarStyleLightContent;\n}\n\n- (void)loadView {\n GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86\n longitude:151.20\n zoom:12];\n GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];\n mapView.myLocationEnabled = YES;\n\n NSBundle *mainBundle = [NSBundle mainBundle];\n NSURL *styleUrl = [mainBundle URLForResource:@\"style\" withExtension:@\"json\"];\n NSError *error;\n\n // Set the map style by passing the URL for style.json.\n GMSMapStyle *style = [GMSMapStyle styleWithContentsOfFileURL:styleUrl error:&error];\n\n if (!style) {\n NSLog(@\"The style definition could not be loaded: %@\", error);\n }\n\n mapView.mapStyle = style;\n self.view = mapView;\n}\n\n@end\n \n```\n\n\u003cbr /\u003e\n\nTo define the style options, add a new file to your project named `style.json`,\nand paste the following JSON style declaration to hide business points of\ninterest (POIs) and public transit icons:\nShow/Hide the JSON. \n\n```text\n[\n {\n \"featureType\": \"poi.business\",\n \"elementType\": \"all\",\n \"stylers\": [\n {\n \"visibility\": \"off\"\n }\n ]\n },\n {\n \"featureType\": \"transit\",\n \"elementType\": \"labels.icon\",\n \"stylers\": [\n {\n \"visibility\": \"off\"\n }\n ]\n }\n]\n```\n\nUsing a string resource\n\nThe following examples show calling `GMSMapStyle()` and passing a string\nresource:\n\n\nSwift \n\n```swift\nclass MapStylingStringResource: UIViewController {\n\n let MapStyle = \"JSON_STYLE_GOES_HERE\"\n\n // Set the status bar style to complement night-mode.\n override var preferredStatusBarStyle: UIStatusBarStyle {\n return .lightContent\n }\n\n override func loadView() {\n let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 14.0)\n let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)\n\n do {\n // Set the map style by passing a valid JSON string.\n mapView.mapStyle = try GMSMapStyle(jsonString: MapStyle)\n } catch {\n NSLog(\"One or more of the map styles failed to load. \\(error)\")\n }\n\n self.view = mapView\n }\n}\n \n```\n\nObjective-C \n\n```objective-c\n@implementation MapStylingStringResource\n\n// Paste the JSON string to use.\nstatic NSString *const kMapStyle = @\"JSON_STYLE_GOES_HERE\";\n\n// Set the status bar style to complement night-mode.\n- (UIStatusBarStyle)preferredStatusBarStyle {\n return UIStatusBarStyleLightContent;\n}\n\n- (void)loadView {\n GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86\n longitude:151.20\n zoom:12];\n GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];\n mapView.myLocationEnabled = YES;\n\n NSError *error;\n\n // Set the map style by passing a valid JSON string.\n GMSMapStyle *style = [GMSMapStyle styleWithJSONString:kMapStyle error:&error];\n\n if (!style) {\n NSLog(@\"The style definition could not be loaded: %@\", error);\n }\n\n mapView.mapStyle = style;\n self.view = mapView;\n}\n\n@end\n \n```\n\n\u003cbr /\u003e\n\nThe following style declaration hides business points of interest (POIs) and\npublic transit icons. Paste the following style string as the value of\nthe `kMapStyle` variable:\nShow/Hide the JSON. \n\n```objective-c\n@\"[\"\n@\" {\"\n@\" \\\"featureType\\\": \\\"poi.business\\\",\"\n@\" \\\"elementType\\\": \\\"all\\\",\"\n@\" \\\"stylers\\\": [\"\n@\" {\"\n@\" \\\"visibility\\\": \\\"off\\\"\"\n@\" }\"\n@\" ]\"\n@\" },\"\n@\" {\"\n@\" \\\"featureType\\\": \\\"transit\\\",\"\n@\" \\\"elementType\\\": \\\"labels.icon\\\",\"\n@\" \\\"stylers\\\": [\"\n@\" {\"\n@\" \\\"visibility\\\": \\\"off\\\"\"\n@\" }\"\n@\" ]\"\n@\" }\"\n@\"]\"\n```\n\nJSON style declarations\n\nStyled maps use two concepts to apply colors and other style changes to a\nmap:\n\n- **Selectors** specify the geographic components that you can style on the map. These include roads, parks, bodies of water, and more, as well as their labels. The selectors include *features* and *elements* , specified as `featureType` and `elementType` properties.\n- **Stylers** are color and visibility properties that you can apply to map elements. They define the displayed color through a combination of hue, color, and lightness/gamma values.\n\nSee the [style reference](/maps/documentation/ios-sdk/style-reference) for a detailed description of the\nJSON styling options.\n\nMaps Platform Styling Wizard \n[](https://mapstyle.withgoogle.com) \n[](https://mapstyle.withgoogle.com) \n[](https://mapstyle.withgoogle.com)[](https://mapstyle.withgoogle.com/) \n[](https://mapstyle.withgoogle.com/) \n[](https://mapstyle.withgoogle.com/) \n[](https://mapstyle.withgoogle.com/) \n[](https://mapstyle.withgoogle.com/) \n[](https://mapstyle.withgoogle.com/) \n[Create\ncustom styles for the Google Maps Platform APIs](https://mapstyle.withgoogle.com)\n\nUse the [Maps Platform Styling Wizard](https://mapstyle.withgoogle.com) as a quick way\nto generate a JSON styling object. The Maps SDK for iOS supports the\nsame style declarations as the Maps JavaScript API.\n\nFull code samples\n\nThe [ApiDemos repository](https://github.com/googlemaps-samples/maps-sdk-for-ios-samples) on GitHub includes\nsamples that demonstrate the use of styling."]]