שיטות מומלצות לאינטראקציה עם מפות Google
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
בדף הזה מוסברות שיטות מומלצות לאינטראקציה עם האובייקט GoogleMap
באפליקציה.
הטמעה של תכונות של GoogleMap
באותו מופע של מפות
ממשקי ה-API של מפות Google זמינים גם כחלק מ-Navigation SDK, שבו אפשר להשתמש כדי ליצור חוויות ספציפיות למפות (לא ניווט). אם האפליקציה כוללת חוויית שימוש במפה ללא ניווט וחוויית ניווט, מומלץ להשתמש ב-API של מפות וניווט באותו מופע של מפה.
משתמשים ב-getMapAsync
כדי לקבל את מופע GoogleMap
אפשר לקבל אובייקט GoogleMap
באמצעות SupportNavigationFragment#getMapAsync
או NavigationView#getMapAsync
. מומלץ להשתמש בשיטה הזו במקום להסתמך על מופע GoogleMap
שעשוי להיות לא עדכני אחרי שמופע NavigationView
הבסיסי נוצר מחדש.
בנוסף, חשוב לנקות את GoogleMap
שאוחזר באמצעות השיטה הזו אחרי שלא צריך אותו יותר. מידע נוסף זמין במאמר בנושא שיטות מומלצות לניקוי מופעים.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-31 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-31 (שעון UTC)."],[[["\u003cp\u003eImplement \u003ccode\u003eGoogleMap\u003c/code\u003e features on a separate map instance from navigation experiences to avoid conflicts and optimize performance.\u003c/p\u003e\n"],["\u003cp\u003eUse \u003ccode\u003egetMapAsync\u003c/code\u003e to retrieve the \u003ccode\u003eGoogleMap\u003c/code\u003e object instead of holding onto an instance, ensuring you have the most up-to-date map object and preventing stale data.\u003c/p\u003e\n"],["\u003cp\u003eRemember to clean up the \u003ccode\u003eGoogleMap\u003c/code\u003e object after use to prevent memory leaks and maintain optimal app performance, referring to the Instance cleanup best practices for detailed guidance.\u003c/p\u003e\n"]]],[],null,["# GoogleMap interaction best practices\n\nThis page explains best practices for interacting with the `GoogleMap` object in\nyour app.\n\nImplement `GoogleMap` features on the same maps instance\n--------------------------------------------------------\n\nMaps APIs are also available as part of Navigation SDK, which you can use to\nbuild map specific (non-navigation) experiences. If your app includes both a\nnon-navigation map experience and a navigation experience, we recommend using\nthe Maps and Navigation API on the same map instance.\n\nUse `getMapAsync` to obtain the `GoogleMap` instance\n----------------------------------------------------\n\nYou can obtain a `GoogleMap` object using either\n`SupportNavigationFragment#getMapAsync` or `NavigationView#getMapAsync`. We\nrecommend this method over holding onto the `GoogleMap` instance that might\nbecome stale once the `NavigationView` underneath is recreated.\n\nAlso be sure to clean up the `GoogleMap` retrieved from this method after it is\nno longer needed. For more information, see [Instance cleanup best\npractices](/maps/documentation/navigation/android-sdk/instance-cleanup-best-practices)."]]