הוספת ספריית התמיכה של SDK של מפות ל-iOS לפרויקט Xcode
כדי להוסיף את ספריית התשתית לסביבת העבודה ב-Xcode:
שימוש ב-Swift Package Manager
אם עדיין אין לכם פרויקט Xcode, אתם יכולים ליצור אחד עכשיו ולשמור אותו במחשב המקומי.
(אם אתם מפתחים מתחילים ב-iOS, יוצרים פרויקט חדש ובוחרים בתבנית של אפליקציית iOS. ב-Xcode 11.7 ואילך, יוצרים אפליקציה עם תצוגה אחת.)
מוסיפים את ה-SDK של מפות ל-iOS כיחס תלות. אפשרויות נוספות מפורטות בקטע התקנת ה-SDK.
בפרויקט ב-Xcode, עוברים אל File -> Swift Packages
-> Add Package Dependency.
בחלון שמופיע, מזינים את כתובת ה-URL של המאגר של ספריית התכונות של SDK של מפות ל-iOS
https://github.com/googlemaps/google-maps-ios-utils ובוחרים באפשרות הבא.
בשלב הזה יכול להיות שתתבקשו לבצע אימות באמצעות חשבון GitHub. כדי להמשיך בתהליך, פועלים לפי ההוראות ליצירת אסימון גישה אישי ל-GitHub.
בחלון הבא, בוחרים באפשרות Version (גרסה), בוחרים באפשרות Up to Next Major Version (עד לגרסה הראשית הבאה) מהתפריט הנפתח ומזינים את הגרסה העדכנית ביותר של Maps SDK לספריית התכונות של iOS (לדוגמה, 6.0.0).
לוחצים על התפריט הנפתח לצד Add to Project (הוספה לפרויקט), בוחרים את הפרויקט ואז בוחרים באפשרות Add Package (הוספת חבילת קוד).
שימוש ב-CocoaPods
אם עדיין אין לכם פרויקט Xcode, אתם יכולים ליצור אחד עכשיו ולשמור אותו במחשב המקומי. (אם אתם מפתחים iOS בפעם הראשונה, תוכלו ליצור אפליקציה עם תצוגה אחת).
אם עדיין אין לכם קובץ pod בפרויקט, יוצרים קובץ בשם Podfile בספריית הפרויקט. הקובץ הזה מגדיר את יחסי התלות של הפרויקט.
עורכים את קובץ ה-pod של הפרויקט ומוסיפים יחסי תלות ל-pod Google-Maps-iOS-Utils. הנה דוגמה שכוללת את יחסי התלות הנדרשים ל-SDK של מפות ל-iOS ולספריית התשתית:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '16.0'
target 'YOUR_APPLICATION_TARGET_NAME_HERE' do
use_frameworks!
pod 'GoogleMaps', '10.0.0'
pod 'Google-Maps-iOS-Utils', '6.1.2' # x-release-please-version
end
מריצים את pod install.
סוגרים את Xcode ופותחים (לחיצה כפולה) את הקובץ .xcworkspace של הפרויקט כדי להפעיל את Xcode. מעכשיו והלאה, צריך להשתמש בקובץ .xcworkspace כדי לפתוח את הפרויקט.
הערה: הכלי לאשכולות של סמנים תלוי בעץ ה-Quadtree, אבל אפשר להשתמש בעץ ה-Quadtree בלי אשכולות של סמנים. אם רוצים להשתמש רק בכלי quadtree, אפשר לשנות את הערך של pod 'Google-Maps-iOS-Utils' ל-'Google-Maps-iOS-Utils/QuadTree' בקובץ ה-pod.
הוספת מפתח ה-API לאפליקציה
במאמר הגדרת פרויקט Xcode מוסבר איך ליצור מפתח API ולהוסיף אותו לפרויקט Xcode.
פיתוח והרצה של הפרויקט
אחרי שמוסיפים את מפתח ה-API, בונים ומריצים את הפרויקט.
שימוש בכלי באפליקציה
במסמכי התיעוד של כל כלי תוכלו לקרוא מידע נוסף על השימוש בו באפליקציה:
פותחים חלון טרמינל, עוברים לספרייה שבה הרחבת את קובצי הדוגמה ומתעדים לספריית הדוגמאות המתאימה לשפה שבה רוצים להשתמש:
ב-Swift, מריצים את הפקודה cd google-maps-ios-utils-master/samples/SwiftDemoApp
עבור Objective-C, מריצים את הפקודה cd google-maps-ios-utils-master/samples/ObjCDemoApp
מריצים את הפקודה הבאה:
pod install
סוגרים את Xcode ופותחים (לחיצה כפולה) את הקובץ .xcworkspace של הפרויקט כדי להפעיל את Xcode. מעכשיו והלאה, צריך להשתמש בקובץ .xcworkspace כדי לפתוח את הפרויקט.
הוספת מפתח ה-API לאפליקציית הדגמה
בקטע קבלת מפתח API, יצרתם מפתח API לאפליקציה. עכשיו מוסיפים את המפתח הזה לפרויקט Xcode של אפליקציית הדגמה.
Swift
מוסיפים את מפתח ה-API ל-AppDelegate.swift באופן הבא:
מוסיפים את הצהרת הייבוא הבאה:
importGoogleMaps
עורכים את השורה הבאה ומוסיפים את מפתח ה-API בין המירכאות הכפולות:
// Change this key to a valid key registered with the demo app bundle id.letmapsAPIKey=""
Objective-C
מוסיפים את מפתח ה-API ל-AppDelegate.m באופן הבא:
מוסיפים את הצהרת הייבוא הבאה:
@importGoogleMaps;
עורכים את השורה הבאה ומוסיפים את מפתח ה-API בין המירכאות הכפולות:
// Change this key to a valid key registered with the demo app bundle id.staticNSString*constkMapsAPIKey=@"";
פיתוח והרצה של אפליקציית ההדגמה
אחרי שמוסיפים את מפתח ה-API, בונים ומריצים את הפרויקט:
אם אתם מפעילים את גרסת Swift של הדמו, תוכלו לבחור איזו תוכנה להציג באפליקציה.
אם מריצים את גרסת Objective-C של הדמו, יוצג הדמו של הכלי לצבירה של סמנים. לאחר מכן תוכלו לערוך את גרסת Objective-C של הדמו כדי לנסות כל כלי.
מידע נוסף זמין בקטע הוספת כלי לשימוש ל-App שבהמשך.
[null,null,["עדכון אחרון: 2025-07-26 (שעון UTC)."],[[["\u003cp\u003eThis documentation guides you on setting up and utilizing the Google Maps SDK for iOS Utility Library, offering tools like marker clustering, quadtrees, and data rendering.\u003c/p\u003e\n"],["\u003cp\u003eYou can integrate the library into your Xcode project using Swift Package Manager or CocoaPods, then access utilities for enhanced map functionalities.\u003c/p\u003e\n"],["\u003cp\u003eA demo app is available for exploring these utilities; you can install it via GitHub or CocoaPods and add your API key for testing.\u003c/p\u003e\n"],["\u003cp\u003eBefore running the demo app or your own project, ensure you have a valid API key and potentially adjust bundle identifiers for application restrictions.\u003c/p\u003e\n"],["\u003cp\u003eDetailed instructions and code examples are provided for both Swift and Objective-C to facilitate seamless integration and usage of the library.\u003c/p\u003e\n"]]],["To integrate the Maps SDK for iOS Utility Library, you can add it to an existing Xcode project via Swift Package Manager or CocoaPods. This involves adding the library's repository URL or pod dependency, selecting the desired version, and running the installation. Alternatively, you can install and run a demo app by downloading the code from GitHub, installing the dependencies with `pod install`, and adding your API key. Finally you can build and run the project.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/utility/setup \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/utility/setup \"View this page for the iOS platform docs.\")\n\nThis page describes how to set up the\n[utility library\nfor the Maps SDK for iOS](https://github.com/googlemaps/google-maps-ios-utils).\n\nTo try these utilities, you can either:\n\n- [Install the utility library's into an existing Xcode project](#get-utility). Add these utilities in your own project.\n- [Install and run the demo app](#get-demo). The demo app is a standalone project that contains all of the code required to try out the utilities.\n\nAdd the Maps SDK for iOS Utility Library to an Xcode project\n\nFollow these steps to add the utility library to your Xcode workspace: \n\nUse Swift Package Manager\n\n1. If you don't have an Xcode project yet, create one now and save it to your local machine. (If you're new to iOS development, create a new project and select the **iOS App\n template** . On Xcode 11.7 or older, create a **Single View Application**.)\n2. Add the Maps SDK for iOS as a dependency. See [Installing the SDK](/maps/documentation/ios-sdk/config#download-sdk) for options.\n3. In your Xcode project, navigate to **File** -\\\u003e **Swift Packages** -\\\u003e **Add Package Dependency**.\n4. In the presented window, enter the Maps SDK for iOS Utility Library repository URL `https://github.com/googlemaps/google-maps-ios-utils` and select **Next**.\n - At this point, you may be prompted to authenticate with your GitHub account. Follow the instructions to create a [GitHub\n personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) to continue the process.\n5. In the next window, select the **Version** radio option, select **Up to Next Major Version** from the drop-down list, and enter the latest [version](https://github.com/googlemaps/google-maps-ios-utils/releases) of the Maps SDK for iOS Utility Library (for example, \"6.0.0\").\n6. Click the drop-down next to **Add to Project** , select your project, and select **Add Package**.\n\nUse CocoaPods\n\n1. If you don't have an Xcode project yet, create one now and save it to your local machine. (If you're new to iOS development, create a *Single\n View Application*.)\n2. If you don't already have a pod file for your project, create a file named `Podfile` in your project directory. This file defines your project's dependencies.\n3. Edit your project's pod file and add a dependency on the `Google-Maps-iOS-Utils` pod. Here is an example which includes the dependencies you need for the Maps SDK for iOS and the utility library: \n\n ```scdoc\n source 'https://github.com/CocoaPods/Specs.git'\n platform :ios, '16.0'\n\n target 'YOUR_APPLICATION_TARGET_NAME_HERE' do\n use_frameworks!\n pod 'GoogleMaps', '10.0.0'\n pod 'Google-Maps-iOS-Utils', '6.1.2' # x-release-please-version\n end\n ```\n4. Run `pod install`.\n5. Close Xcode, and then open (double-click) your project's `.xcworkspace` file to launch Xcode. From this time onwards, you must use the `.xcworkspace` file to open the project.\n\n**Note:** The marker clustering utility is dependent on the\nquadtree, but you can use the quadtree without marker clustering. If you want\nonly the quadtree utility, you can change\n`pod 'Google-Maps-iOS-Utils'` to\n`'Google-Maps-iOS-Utils/QuadTree'` in your pod file.\n\nAdd the API key to your app See [Set up an Xcode Project](/maps/documentation/ios-sdk/config) for instructions on generating an API key and adding it to your Xcode project.\n\nBuild and run the project\n\nAfter you add the API key, build and run the project.\n\nUse a utility in your app\n\nSee the documentation on each utility for more information on using it in your app:\n\n- [Marker\n clustering](/maps/documentation/ios-sdk/utility/marker-clustering)\n- [Quadtree](/maps/documentation/ios-sdk/utility/quadtree)\n- [KML rendering](/maps/documentation/ios-sdk/utility/kml)\n- [GeoJSON rendering](/maps/documentation/ios-sdk/utility/geojson)\n- [Heatmap](/maps/documentation/ios-sdk/utility/heatmap)\n\nInstall and run the demo app\n\nThe utility library includes a demo app that you can install and then try out each utility.\nInstall the demo app: \n\nUse files from GitHub\n\n1. [Download\n the code sample archive](https://github.com/googlemaps/google-maps-ios-utils/archive/master.zip) from [GitHub](https://github.com/googlemaps/google-maps-ios-utils/tree/master/samples) and unpack the archive.\n2. Open a terminal window, navigate to the directory where you expanded the sample files, and drill down into the appropriate samples directory for the language you want to use:\n - For Swift, run `cd google-maps-ios-utils-master/samples/SwiftDemoApp`\n - For Objective-C, run `cd google-maps-ios-utils-master/samples/ObjCDemoApp`\n3. Run the following command: \n\n ```text\n pod install\n ```\n4. Close Xcode, and then open (double-click) your project's `.xcworkspace` file to launch Xcode. From this time onwards, you must use the `.xcworkspace` file to open the project.\n\nAdd the API key to the demo app In [Get an API key](/maps/documentation/ios-sdk/get-api-key), you generate an API key for your app. Now add that key to the Xcode project for the demo app. **Note:** If your API key uses an **Application restriction** , ensure that you add the bundle identifier of your app to the key. For example, if you are running the demo app, the bundle identifier is `com.google.gmsutils.DemoApp`. See [Get an API key](/maps/documentation/ios-sdk/get-api-key) for more information on restricting a key. \n\nSwift\n\nAdd your API key to your `AppDelegate.swift` as follows:\n\n1. Add the following import statement: \n\n ```swift\n import GoogleMaps\n ```\n2. Edit the following line to add your API key between the double quotes: \n\n ```swift\n // Change this key to a valid key registered with the demo app bundle id.\n let mapsAPIKey = \"\"\n ```\n\nObjective-C\n\nAdd your API key to your `AppDelegate.m` as follows:\n\n1. Add the following import statement: \n\n ```objective-c\n @import GoogleMaps;\n ```\n2. Edit the following line to add your API key between the double quotes: \n\n ```objective-c\n // Change this key to a valid key registered with the demo app bundle id.\n static NSString *const kMapsAPIKey = @\"\";\n ```\n\nBuild and run the demo app\n\nAfter you add the API key, build and run the project:\n\n- If you are running the Swift version of the demo, you can select which utility to view in the app.\n- If you are running the Objective-C version of the demo, you see the demo of the marker clustering utility. You can then edit the Objective-C version of the demo to try each utility. See the [Add a utility to your app](#add_utility) section below for more information."]]