Sprawdzone metody dotyczące interakcji z Mapami Google
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Na tej stronie znajdziesz sprawdzone metody interakcji z obiektem GoogleMap
w aplikacji.
Wdrażanie funkcji GoogleMap
w tej samej instancji Map
Interfejsy API Map są też dostępne w pakiecie Navigation SDK, którego możesz używać do tworzenia funkcji związanych z mapami (nie z nawigacją). Jeśli Twoja aplikacja zawiera zarówno mapę bez nawigacji, jak i nawigację, zalecamy używanie interfejsu Maps and Navigation API na tej samej instancji mapy.
Użyj getMapAsync
, aby uzyskać instancję GoogleMap
Obiekt GoogleMap
możesz uzyskać za pomocą SupportNavigationFragment#getMapAsync
lub NavigationView#getMapAsync
. Zalecamy tę metodę zamiast przechowywania instancji GoogleMap
, która może stać się nieaktualna po ponownym utworzeniu instancji NavigationView
.
Pamiętaj też, aby po zakończeniu korzystania z GoogleMap
pobranego tą metodą usunąć go. Więcej informacji znajdziesz w artykule Sprawdzone metody czyszczenia instancji.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-31 UTC.
[null,null,["Ostatnia aktualizacja: 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)."]]