我正在开发一个带有导航抽屉的项目,其中一个片段应该是谷歌地图。
我正在尝试实现OnMapReadyCallback接口,但它无法解析该符号。
我已尝试更新Google Play服务。 这是我的build.gradle:app
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.zakrzewskibartlomiej.cv_v3"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.google.android.gms:play-services:9.0.1'
compile 'com.google.android.gms:play-services-maps:8.4.0'
}
在这里,我正在努力实现这个
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, onMapReadyCallback {
NavigationView navigationView = null;
Toolbar toolbar = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//set the fragment initially
MainFragment fragment = new MainFragment();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
我该如何解决这个问题?
答案 0 :(得分:4)
错字...你已经输入了这个。
import com.google.android.gms.maps.OnMapReadyCallback;
所以这需要大写
onMapReadyCallback
此外,如果您要使用多个播放服务,请确保您拥有相同版本的播放服务(尽管您似乎只需要地图)
compile 'com.google.android.gms:play-services-maps:9.0.1'
答案 1 :(得分:1)
试试这个
在依赖项列表
中添加此项compile 'com.google.android.gms:play-services-maps:8.4.0'
并重新同步并运行