Use this class to initialize the Google Maps SDK for Android if features need to be used before obtaining a map. It must be called because some classes such as BitmapDescriptorFactory and CameraUpdateFactory need to be initialized.
If you are using MapFragment
or
MapView
and have
already obtained a (non-null) GoogleMap
by
calling getMapAsync()
on either of these classes and waiting for the
onMapReady(GoogleMap map)
callback, then you do not need to worry about this
class. See the sample application for some examples.
Nested Class Summary
enum | MapsInitializer.Renderer | Enables you to specify which MapsInitializer.Renderer
you prefer to use for your application LATEST or
LEGACY . |
Public Method Summary
synchronized static int |
initialize(Context
context, MapsInitializer.Renderer
preferredRenderer,
OnMapsSdkInitializedCallback callback)
Specifies which
MapsInitializer.Renderer
type you prefer to use to initialize the Google Maps SDK for Android, and
provides a callback to receive the actual MapsInitializer.Renderer
type.
|
synchronized static int |
initialize(Context
context)
Initializes the Google Maps SDK for Android so that its classes are ready for
use.
|
Inherited Method Summary
Public Methods
public static synchronized int initialize (Context context, MapsInitializer.Renderer preferredRenderer, OnMapsSdkInitializedCallback callback)
Specifies which MapsInitializer.Renderer
type you prefer to use to initialize the Google Maps SDK for Android, and provides a
callback to receive the actual MapsInitializer.Renderer
type. This call will initialize the Google Maps SDK for Android, so that its classes
are ready for use. The callback will be triggered when the Maps SDK is initialized.
The Maps SDK only initializes once per Application lifecycle. Only the first call of
this method or
initialize(Context)
takes effect. If you are using MapFragment
or MapView
and
have already obtained a (non-null) GoogleMap
by
calling getMapAsync()
on either of these classes, then this call will have
no effect other than triggering the callback for the initialized MapsInitializer.Renderer
.
To make renderer preference meaningful, you must call this method before
initialize(Context)
, and before
MapFragment.onCreate(Bundle)
and
MapView.onCreate(Bundle)
. It's recommended to do this in Application.onCreate()
.
Note the following:
- Use
LATEST
to request the new renderer. No action is necessary if you prefer to use the legacy renderer. - The latest renderer may not always be returned due to various reasons, including not enough memory, unsupported Android version, or routine downtime.
- The new renderer will eventually become the default renderer through a
progressive rollout. At that time, you will need to request
LEGACY
in order to continue using the legacy renderer. Check out Google Play Service release notes for rollout progress.
Parameters
context | Required to fetch the necessary SDK resources and code. Must not be
null . |
---|---|
preferredRenderer | Which MapsInitializer.Renderer
type you prefer to use for your application. If null is provided, the
default preference is taken. |
callback | The callback that the Maps SDK triggers when it informs you about which renderer type was actually loaded. You can define what you want to do differently according to the maps renderer that is loaded. |
Returns
- A ConnectionResult error code.
public static synchronized int initialize (Context context)
Initializes the Google Maps SDK for Android so that its classes are ready for use.
If you are using MapFragment
or MapView
and
have already obtained a (non-null) GoogleMap
by
calling getMapAsync()
on either of these classes, then it is not necessary
to call this.
Parameters
context | Required to fetch the necessary SDK resources and code. Must not be
null . |
---|
Returns
- A ConnectionResult error code.