找不到符号方法getMap()

果戈里
private GoogleMap mMap;

我从MainActivity开始一个活动:

@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:在这里找不到符号方法getMap():

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);

    }
}

请帮我解决这个问题!

桑索什·雷迪(Santhosh Reddy)
private void setUpMapIfNeeded() {
        if (mMap == null) {
            SupportMapFragment mapFrag = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
            mapFrag.getMapAsync(this);
            if (mMap != null) {
                setUpMap();
            }
        }
    }  

getMap() 不推荐使用 getMapAsync()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章