Leem
Leem

Reputation: 18308

How to set OnMapReadyCallback to my MapView instance?

I have a Google Map API provided MapView in my layout:

<com.google.android.gms.maps.MapView xmlns:map="http://schemas.android.com/apk/res-auto"
            android:id="@+id/map_view"
...
/>

In my Fragment, I implements OnMapReadyCallback:

public class MyFragment extends Fragment implements OnMapReadyCallback {

    // onCreate, onCreateView are not showing here but I have them.

   @BindView(R.id.map_view)
    MapView mMapView;

   // this is the method form the interface I am implementing.
   @Override
    public void onMapReady(GoogleMap googleMap) {
        Log.d("MyFragment", "map ready!");
    }
}

As you can see above, I have overriden the onMapReady(GoogleMap googleMap) because I am implementing the OnMapReadyCallback interface.

But, How can I set the listener for mMapView to listen to map ready event?

I tried mMapView.setOnMapReadyCallback(this) but there is no such method in MapView.

Upvotes: 0

Views: 352

Answers (1)

Blackbelt
Blackbelt

Reputation: 157437

you can use

getMapAsync(OnMapReadyCallback callback)

Eg, in your case

mMapView.getMapAsync(this);

you can find the documentation here

Upvotes: 1

Related Questions