gpt4 book ai didi

android - mapping.MapView 无法转换为 mapping.SupportMapFragment

转载 作者:行者123 更新时间:2023-11-29 18:36:59 25 4
gpt4 key购买 nike

我只是将这里的 sdk 实现到我的项目中进行第一次测试,但我无法到达任何地方,而且这里的网站上没有 kotlin 支持

try{
mapfragment!!.init { error ->
if (error == OnEngineInitListener.Error.NONE) {
// retrieve a reference of the map from the map fragment

var fragmentMap = mapfragment.map

map = mapfragment.map

// Set the map center to the Vancouver region (no animation)
map!!.setCenter(GeoCoordinate(49.196261, -123.004773, 0.0), Map.Animation.NONE)
// Set the zoom level to the average between min and max
map!!.zoomLevel = (map!!.maxZoomLevel + map!!.minZoomLevel) / 2
} else {
println("ERROR: Cannot initialize Map Fragment")
}
}

}
catch
(e: Exception)
{
Log.e("exception","map",e)
}catch
(ej: java.lang.Exception)
{
Log.e("exception","map",ej)
}

这部分 mapfragment!!.init 给我异常

java.lang.ClassCastException: com.here.android.mpa.mapping.MapView cannot be cast to com.here.android.mpa.mapping.SupportMapFragment

这是我的布局

 <fragment
class="com.here.android.mpa.mapping.SupportMapFragment"
android:id="@+id/mapfragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

最佳答案

正如@David 提到的,我认为您缺少 SupportMapFragment 对象。基本上,您需要链接它。

看看我的,我用这个在 Kotlin 中工作:

var map: Map? = null
var mapRoute: MapRoute? = null

//get mapfragment
fun getSupportMapFragment(): SupportMapFragment {
return getSupportFragmentManager().findFragmentById(R.id.mapfragment) as SupportMapFragment
}

//initializing the map view with default values
fun initializeMap() {
val mapFragment = getSupportMapFragment()
mapFragment.init { error ->
if (error == OnEngineInitListener.Error.NONE) {
// retrieve a reference of the map from the map fragment
map = mapFragment.getMap()
// Set the map center coordinate (no animation) - just to initialize map
map!!.setCenter(GeoCoordinate(0.0, 0.0, 0.0), Map.Animation.NONE)
// Set the map zoom level to the average between min and max (no animation)
map!!.setZoomLevel((map!!.getMaxZoomLevel() + map!!.getMinZoomLevel()))

} else {
println("ERROR: Cannot initialize Map Fragment")
//Log.e(LOG_TAG, "Cannot initialize SupportMapFragment ($error)")
}
}
}

关于android - mapping.MapView 无法转换为 mapping.SupportMapFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53928657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com