gpt4 book ai didi

android - 找不到符号方法 getMap()

转载 作者:行者123 更新时间:2023-11-29 15:40:07 25 4
gpt4 key购买 nike

private GoogleMap mMap;

我从 MainActivity 开始一个类似的 Activity :

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();

if (id == R.id.nav_car) {
Intent detailIntent = new Intent(this, Map_Activity.class);
startActivity(detailIntent);
}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawerLayout);
drawer.closeDrawer(GravityCompat.START);
return true;
}

一切正常,直到我得到 ( Error:(222, 97) error: cannot find symbol method getMap() here:

private void setUpMap() {
if (mMap == null) {
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationChangeListener(this);

}
}

请帮我解决这个问题!

最佳答案

使用 SupportMapFragmentgetMapAsync()

((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
});

你可以找到文档here

关于android - 找不到符号方法 getMap(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42089495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com