【发布时间】:2019-08-17 09:08:33
【问题描述】:
我用谷歌地图活动创建了一个新项目,并安装了谷歌播放服务。我添加了互联网,精细位置和粗略位置的权限。 我复制了 google_maps_api.xml 中提到的 URL,并生成了 google_maps_api.xml 和清单元文件中使用的 API key.API 密钥。 现在我遇到了有关 supportMapFragment 的问题。
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));
}}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-maps:17.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'
implementation 'androidx.core:core:1.0.0'
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
implementation 'androidx.fragment:fragment:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
}
我该如何解决这个问题。请帮助我。
【问题讨论】:
-
将您的应用迁移到 AndroidX 可以解决此问题,请参阅 stackoverflow.com/questions/56963327/…
-
我也这样做了。那个问题已经消失了,但出现了一些新问题。即 1) 无法解析 oncreate android oncreate(android.os.bundle)。 2) 无法解析方法 'setContentView(int)' 3) 无法解析符号 'FragmentActivity' 4) 无法解析方法 'getSupportFragmentManager()'
-
你的app gradle的
compileSdkVersion和buildToolsVersion是什么版本? @Priyanka -
compileSdkVersion 28 defaultConfig { applicationId "com.example.googlemaps1" minSdkVersion 15 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" }
-
请发送 gradle 依赖项? @Priyanka
标签: android google-maps android-studio supportmapfragment