我可以在片段中加载并查看街景视图,但是在加载时会显示黑色空白屏幕。有什么解决方法可以避免在加载时出现黑屏。
这是我放置在XML中以显示Panorama的代码:
<com.mypackagename.CustomStreetViewPanoramaView
android:id="@+id/streetViewPanorama"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/addressLL" />
在initUI的片段中,调用getStreetViewPanoramaAsync
:
override fun initUI() {
streetViewPanorama?.postDelayed({
streetViewPanorama?.onCreate(Bundle())
streetViewPanorama?.getStreetViewPanoramaAsync {
onPanoramaReady(it)
presenter?.getNearByPanorama(50, 0.5f)
}
}, 500)
}
private fun onPanoramaReady(streetViewPanorama: StreetViewPanorama?) {
isPanoramaLoaded = true
panorama = streetViewPanorama
}
从演示者获取位置信息后,设置全景位置,例如:
override fun setPanoramaPosition(locationInfo: LocationInfo, radius: Int, zoom: Float) {
if (isPanoramaLoaded) {
setState(progress = true)
val location = LatLng(locationInfo.latitude, locationInfo.longitude)
panorama?.setPosition(location, radius)
panorama?.isStreetNamesEnabled = true
panorama?.setOnStreetViewPanoramaChangeListener { streetViewPanoramaLocation ->
run {
if (streetViewPanoramaLocation?.links != null) {
// if streetViewPanoramaLocation is present then set camera position
val panoramaLocation = panorama?.location?.position
val heading = SphericalUtil.computeHeading(panoramaLocation, location)
val camera = StreetViewPanoramaCamera.Builder()
.zoom(panorama?.panoramaCamera?.zoom?.plus(zoom)!!)
.tilt(panorama?.panoramaCamera?.tilt!!)
.bearing(panorama?.panoramaCamera?.bearing!!)
.build()
panorama?.animateTo(camera, 100)
setState(progress = false)
} else {
// if streetViewPanoramaLocation not available in 50 meter radius then try with 100 radius
if (radius != 100)
presenter?.getNearByPanorama(100, 0.5f)
else // if not found within 100 meter radius show error message
setState(error = true)
}
}
}
}
}