我是android的新手,想在android studio中创建一个基本的地图应用程序。
仿真器正在加载地图,但灰色显示,左下角只有Google徽标。
指向仿真器图像的链接为https://imgur.com/peygWiq
build.gradle文件在下一行显示红色下划线。
链接到gradle文件https://imgur.com/wgGbW7I
谷歌搜索灰色问题之后,我发现build.gradle文件中存在一些问题。
因此,我检查了关于stackoverflow的各种解决方案,并在build.gradle文件中添加了三行(现在已注释)。
由于堆栈溢出中给出的所有解决方案都无法解决问题,因此将其发布为新问题。
Android Studio版本:3.2.1
//顶层构建文件,您可以在其中添加所有子项目/模块共有的配置选项。
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// Module:app
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.krishnaji.mapfun"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
// implementation 'com.android.support:design:28.0.0'
// implementation 'com.android.support:support-media-compat:28.0.0'
// implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
}
// MainActivity.java
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is
ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker
in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
Toast.makeText(this, "Welcome to Maps", Toast.LENGTH_LONG).show();
}
}
想查看在模拟器上显示的地图上标记的悉尼。 PS:我可以看到Toast欢迎使用Google地图,但是地图是灰色的