توضح هذه الصفحة كيفية عرض البيانات الجغرافية في ملف KML
باستخدام GMUKMLParser في
بالتزامن مع GMUGeometryRenderer. يعد KML ملف
لعرض البيانات الجغرافية مثل النقاط والخطوط والمضلّعات.
توضح لقطة الشاشة التالية بعض الأمثلة على بيانات KML المعروضة على إحدى الخرائط:
للاطّلاع على عيّنة الرموز الكاملة، يُرجى مراجعة نماذج التطبيقات
تشغيل
GitHub.
عرض بيانات KML
لعرض بيانات KML على خريطة، يمكنك إنشاء GMUKMLParser باستخدام
إلى مورد KML (KML_Sample.kml في هذا المثال). بعد ذلك، يُرجى اتّباع الخطوات التالية:
إنشاء GMUGeometryRenderer لتجتاز GMUKMLParser
مثال. وأخيرًا، اتصِل بالرقم GMUGeometryRenderer.render(). تشير رسالة الأشكال البيانية
يوضح مثال الرمز التالي عرض بيانات KML على خريطة:
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis documentation explains how to render geographic data in KML format using the \u003ccode\u003eGMUKMLParser\u003c/code\u003e and \u003ccode\u003eGMUGeometryRenderer\u003c/code\u003e within the Google Maps SDK for iOS Utility Library.\u003c/p\u003e\n"],["\u003cp\u003eKML is a popular format used for displaying geographic data, including points, lines, and polygons, on maps.\u003c/p\u003e\n"],["\u003cp\u003eTo render KML data, create a \u003ccode\u003eGMUKMLParser\u003c/code\u003e instance with the path to your KML file, then use it to initialize a \u003ccode\u003eGMUGeometryRenderer\u003c/code\u003e, and finally, call \u003ccode\u003erender()\u003c/code\u003e on the renderer to display the data on your map.\u003c/p\u003e\n"],["\u003cp\u003eCode examples in both Swift and Objective-C are provided to demonstrate the process of rendering KML data on a map using the Google Maps SDK for iOS.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/maps/documentation/android-sdk/utility/kml \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/utility/kml \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/kmllayer \"View this page for the JavaScript platform docs.\")\n\nThis page shows you how to render geographic data in the KML\nformat, using `GMUKMLParser` in\nconjunction with `GMUGeometryRenderer`. KML is a popular\nformat for rendering geographic data such as points, lines, and polygons.\n\nThe following screenshot shows some example KML data rendered on a map:\n\nPrerequisites and notes\n\n`GMUKMLParser` is part of\nthe [Maps SDK for iOS Utility Library](https://github.com/googlemaps/google-maps-ios-\nutils). If you haven't yet set up\nthe library, follow the [setup guide](/maps/documentation/ios-\nsdk/utility/setup) before reading the rest of this page.\n\nFor the full code sample, see the sample apps\n[on\nGitHub](https://github.com/googlemaps/google-maps-ios-utils).\n\nRendering KML data\n\nTo render KML data on a map, create a `GMUKMLParser` with the\npath to a KML resource (`KML_Sample.kml` in this example). Then,\ncreate a `GMUGeometryRenderer` passing the `GMUKMLParser`\ninstance. Finally, call `GMUGeometryRenderer.render()`. The\nfollowing code example shows rendering KML data on a map: \n\nSwift \n\n```swift\nimport GoogleMapsUtils\n\nclass KML: NSObject {\n private var mapView: GMSMapView!\n\n func renderKml() {\n guard let path = Bundle.main.path(forResource: \"KML_Sample\", ofType: \"kml\") else {\n print(\"Invalid path\")\n return\n }\n\n let url = URL(fileURLWithPath: path)\n\n let kmlParser = GMUKMLParser(url: url)\n kmlParser.parse()\n\n let renderer = GMUGeometryRenderer(\n map: mapView,\n geometries: kmlParser.placemarks,\n styles: kmlParser.styles\n )\n\n renderer.render()\n }\n}\n \n```\n\nObjective-C \n\n```objective-c\n@import GoogleMapsUtils;\n\n@implementation KML {\n GMSMapView *_mapView;\n}\n\n- (void)renderKml {\n NSString *path = [[NSBundle mainBundle] pathForResource:@\"KML_Sample\" ofType:@\"kml\"];\n NSURL *url = [NSURL fileURLWithPath:path];\n GMUKMLParser *parser = [[GMUKMLParser alloc] initWithURL:url];\n [parser parse];\n GMUGeometryRenderer *renderer = [[GMUGeometryRenderer alloc] initWithMap:_mapView\n geometries:parser.placemarks\n styles:parser.styles];\n [renderer render];\n}\n\n@end\n \n```"]]