I have looked online to find a solution as getMap() method is Deprecated, therefore, I would like to replace it with getMapAsync();. I have searched on google as well as androids official documentations and I am still stuck please help.
I am now getting one error message which says incompatible type Required com.google.android.gms.GoogleMap found void.
public class Maps extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap googleMap;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Maps);
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.mapFragment)).getMapAsync(this);
LatLng latlong = new LatLng(lat, lon);
googleMap.addMarker(new MarkerOptions().position(latlong).title(name));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlong, 15));
}
@Override
public void onMapReady(GoogleMap googleMap) {
}
}
This method below gives the error and it says incompatible type Required com.google.android.gms.GoogleMap found void.
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.mapFragment)).getMapAsync(this);
getMapAsync
has as return type void, and you are trying to assign it
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.mapFragment)).getMapAsync(this);
to googleMap
. Which doesn't make much sense. Call only getMapAsync
like
((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.mapFragment)).getMapAsync(this);
and assign googleMap
when onMapReady
is invoked. E.g.
@Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With