بهترین شیوه های تعامل GoogleMap
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این صفحه بهترین روشها را برای تعامل با شی GoogleMap
در برنامه شما توضیح میدهد.
ویژگی های GoogleMap
را در همان نمونه نقشه پیاده سازی کنید
API های Maps نیز به عنوان بخشی از Navigation SDK در دسترس هستند که می توانید از آنها برای ایجاد تجربیات خاص نقشه (غیر ناوبری) استفاده کنید. اگر برنامه شما شامل یک تجربه نقشه غیر ناوبری و یک تجربه ناوبری است، توصیه می کنیم از Maps and Navigation API در یک نمونه نقشه استفاده کنید.
از getMapAsync
برای به دست آوردن نمونه GoogleMap
استفاده کنید
میتوانید با استفاده از SupportNavigationFragment#getMapAsync
یا NavigationView#getMapAsync
یک شی GoogleMap
دریافت کنید. توصیه میکنیم این روش را بیش از نگه داشتن نمونه GoogleMap
که ممکن است پس از بازسازی NavigationView
در زیر آن کهنه شود، نگه دارید.
همچنین مطمئن شوید که GoogleMap
بازیابی شده از این روش را بعد از اینکه دیگر مورد نیاز نیست، پاک کنید. برای اطلاعات بیشتر، به بهترین شیوه پاکسازی نمونه مراجعه کنید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-09-03 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-09-03 بهوقت ساعت هماهنگ جهانی."],[[["\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)."]]