OnMapReadyCallback
Stay organized with collections
Save and categorize content based on your preferences.
Callback interface for when the map is ready to be used.
Once an instance of this interface is set on a MapFragment
or MapView
object, the onMapReady(GoogleMap)
method is triggered when the map is ready to be used and
provides a non-null instance of GoogleMap
.
If Google Play services is not installed on the device, the user will be prompted to
install it, and the onMapReady(GoogleMap)
method will only be triggered when the user has installed it
and returned to the app.
Public Methods
public abstract void
onMapReady
( GoogleMap
googleMap)
Called when the map is ready to be used.
Note that this does not guarantee that the map has undergone layout. Therefore, the
map's size may not have been determined by the time the callback method is called. If
you need to know the dimensions or call a method in the API that needs to know the
dimensions, get the map's View
and register
an ViewTreeObserver.OnGlobalLayoutListener
as well.
Do not chain the OnMapReadyCallback
and OnGlobalLayoutListener
listeners, but instead register and wait for both
callbacks independently, since the callbacks can be fired in any order.
As an example, if you want to update the map's camera using a LatLngBounds
without dimensions, you should wait until both OnMapReadyCallback
and OnGlobalLayoutListener
have completed. Otherwise there is a race condition
that could trigger an IllegalStateException
.
Parameters
googleMap
A non-null instance of a GoogleMap associated with the MapFragment
or MapView
that defines the callback.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eOnMapReadyCallback\u003c/code\u003e is triggered when the Google Map is ready to be used within a \u003ccode\u003eMapFragment\u003c/code\u003e or \u003ccode\u003eMapView\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt provides a non-null \u003ccode\u003eGoogleMap\u003c/code\u003e object in the \u003ccode\u003eonMapReady\u003c/code\u003e method for developers to interact with.\u003c/p\u003e\n"],["\u003cp\u003eIf Google Play services is missing, users will be prompted to install it before the callback is triggered.\u003c/p\u003e\n"],["\u003cp\u003eMap layout and dimensions may not be immediately available in \u003ccode\u003eonMapReady\u003c/code\u003e, requiring additional handling with \u003ccode\u003eViewTreeObserver.OnGlobalLayoutListener\u003c/code\u003e for size-dependent operations.\u003c/p\u003e\n"],["\u003cp\u003eAvoid chaining \u003ccode\u003eOnMapReadyCallback\u003c/code\u003e and \u003ccode\u003eOnGlobalLayoutListener\u003c/code\u003e, instead register and wait for both independently to prevent potential race conditions.\u003c/p\u003e\n"]]],[],null,["# OnMapReadyCallback\n\npublic interface **OnMapReadyCallback** \nCallback interface for when the map is ready to be used.\n\nOnce an instance of this interface is set on a [MapFragment](/android/reference/com/google/android/gms/maps/MapFragment) or\n[MapView](/android/reference/com/google/android/gms/maps/MapView) object, the\n[onMapReady(GoogleMap)](/android/reference/com/google/android/gms/maps/OnMapReadyCallback#onMapReady(com.google.android.gms.maps.GoogleMap)) method is triggered when the map is ready to be used and\nprovides a non-null instance of [GoogleMap](/android/reference/com/google/android/gms/maps/GoogleMap).\n\nIf Google Play services is not installed on the device, the user will be prompted to\ninstall it, and the [onMapReady(GoogleMap)](/android/reference/com/google/android/gms/maps/OnMapReadyCallback#onMapReady(com.google.android.gms.maps.GoogleMap)) method will only be triggered when the user has installed it\nand returned to the app. \n\n### Public Method Summary\n\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [onMapReady](/android/reference/com/google/android/gms/maps/OnMapReadyCallback#onMapReady(com.google.android.gms.maps.GoogleMap))([GoogleMap](/android/reference/com/google/android/gms/maps/GoogleMap) googleMap) Called when the map is ready to be used. |\n\nPublic Methods\n--------------\n\n#### public abstract void **onMapReady** ([GoogleMap](/android/reference/com/google/android/gms/maps/GoogleMap) googleMap)\n\nCalled when the map is ready to be used.\n\nNote that this does not guarantee that the map has undergone layout. Therefore, the\nmap's size may not have been determined by the time the callback method is called. If\nyou need to know the dimensions or call a method in the API that needs to know the\ndimensions, get the map's [View](//developer.android.com/reference/android/view/View.html) and register\nan [ViewTreeObserver.OnGlobalLayoutListener](//developer.android.com/reference/android/view/ViewTreeObserver.OnGlobalLayoutListener.html) as well.\n\nDo not chain the `OnMapReadyCallback` and\n`OnGlobalLayoutListener` listeners, but instead register and wait for both\ncallbacks independently, since the callbacks can be fired in any order.\n\nAs an example, if you want to update the map's camera using a [LatLngBounds](/android/reference/com/google/android/gms/maps/model/LatLngBounds)\nwithout dimensions, you should wait until both `OnMapReadyCallback` and\n`OnGlobalLayoutListener` have completed. Otherwise there is a race condition\nthat could trigger an [IllegalStateException](//developer.android.com/reference/java/lang/IllegalStateException.html). \n\n##### Parameters\n\n| googleMap | A non-null instance of a GoogleMap associated with the [MapFragment](/android/reference/com/google/android/gms/maps/MapFragment) or [MapView](/android/reference/com/google/android/gms/maps/MapView) that defines the callback. |\n|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|"]]