首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能将mapping.MapView转换为mapping.SupportMapFragment

不能将mapping.MapView转换为mapping.SupportMapFragment
EN

Stack Overflow用户
提问于 2018-12-26 07:11:19
回答 2查看 212关注 0票数 1

我只是在我的第一次测试项目中实现了这里的sdk,但是我无法获得任何地方,在这里的网站上没有kotlin支持。

代码语言:javascript
复制
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给了我一个例外

com.here.android.mpa.mapping.SupportMapFragment :不能将java.lang.ClassCastException转换为com.here.android.mpa.mapping.MapView

这是我的布局

代码语言:javascript
复制
 <fragment
        class="com.here.android.mpa.mapping.SupportMapFragment"
        android:id="@+id/mapfragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-19 19:02:49

正如@David所提到的,我认为您缺少了SupportMapFragment对象。基本上你得把它联系起来。

看看我的,我在科特林工作用这个:

代码语言:javascript
复制
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)")
        }
    }
}
票数 1
EN

Stack Overflow用户

发布于 2018-12-26 07:20:30

你是怎么得到变量地图的?在您的视图中,布局映射片段似乎是MapView类型,而不是SupportMapFrgment类型。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53928657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档