我有一个带有2个活动的应用程序,显示Google Maps。该地图由两个活动通过一个包含的片段共享。问题是Google地图的部分加载。
我已经检查了API密钥,将API密钥限制为App SHA-1(并且还尝试了不受限制的密钥)。我正在将Kotlin与Android Studio 3.4.1和AndroidX一起使用。
Google地图布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
活动中包含的地图显示在屏幕截图上:
<include
layout="@layout/fragment_map"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/include"
tools:context=".ui.features.domain.DomainMapActivity" />
活动代码:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.AppTheme)
setContentView(R.layout.activity_domain_map)
bindViews()
init()
initMap()
}
private fun init() {
val bundle: Bundle? = intent.extras
bundle?.let { it ->
domainLocation = it.getParcelable("domain_location")
wineID = it.getString("wine_id")
domainName = it.getString("domain_name")
domainName?.let {
mToolbarLogo = mToolbar.findViewById(R.id.toolbar_logo)
mToolbarTitle = mToolbar.findViewById(R.id.toolbar_title)
mToolbarLogo.visibility = View.GONE
mToolbarTitle.visibility = View.VISIBLE
mToolbarTitle.text = it
}
}
}
private fun initMap() {
try {
val options = GoogleMapOptions()
options.mapType(GoogleMap.MAP_TYPE_TERRAIN)
.compassEnabled(false)
.rotateGesturesEnabled(true)
.scrollGesturesEnabled(true)
.tiltGesturesEnabled(true)
mapFragment = SupportMapFragment.newInstance(options)
val ft = supportFragmentManager.beginTransaction()
ft.replace(R.id.map, mapFragment)
ft.commit()
mapFragment.getMapAsync(this@DomainMapActivity)
} catch (e: NullPointerException) {
Log.e(TAG, e.localizedMessage)
}
}
override fun onMapReady(googleMap: GoogleMap?) {
mMap = googleMap
mMap?.setOnMapClickListener(this)
mMap?.setOnMarkerClickListener(this)
mMap?.setOnCameraMoveListener(this)
if (checkPermission()) {
mMap?.isMyLocationEnabled = true
mMap?.uiSettings?.isMyLocationButtonEnabled = true
} else askPermission()
//Ensure the location to pass is not null
domainLocation?.let {
setCurrentLocation(it)
}
}
实际结果:
1 https://imgur.com/QhCXCEw(输入“活动”,缩放15)
2 https://imgur.com/urhQiFh(缩小,没有详细信息)
3 https://imgur.com/gXoQzcm(缩小,我当前的位置)
进入活动时的预期结果:4:https://imgur.com/lA9UAa4“用户位置(我当前的位置)以及进入活动时我要做什么(正确显示)”