Praktik terbaik interaksi GoogleMap
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan praktik terbaik untuk berinteraksi dengan objek GoogleMap
di
aplikasi Anda.
Menerapkan fitur GoogleMap
pada instance peta yang sama
Maps API juga tersedia sebagai bagian dari Navigation SDK, yang dapat Anda gunakan untuk membangun pengalaman khusus peta (non-navigasi). Jika aplikasi Anda menyertakan pengalaman peta non-navigasi dan pengalaman navigasi, sebaiknya gunakan Maps and Navigation API pada instance peta yang sama.
Gunakan getMapAsync
untuk mendapatkan instance GoogleMap
Anda dapat memperoleh objek GoogleMap
menggunakan
SupportNavigationFragment#getMapAsync
atau NavigationView#getMapAsync
. Kami
merekomendasikan metode ini daripada mempertahankan instance GoogleMap
yang mungkin
menjadi tidak valid setelah NavigationView
di bawahnya dibuat ulang.
Pastikan juga untuk membersihkan GoogleMap
yang diambil dari metode ini setelah tidak lagi diperlukan. Untuk mengetahui informasi selengkapnya, lihat Praktik terbaik pembersihan instance.
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-08-31 UTC.
[null,null,["Terakhir diperbarui pada 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)."]]