【问题标题】:Using geo location Google maps api v2使用地理位置 Google maps api v2
【发布时间】:2013-03-23 20:46:46
【问题描述】:

我已向我的应用程序添加了一个地图片段,其中包括一个地理标记并包含我的播放服务 jar,但我的标记代码出现以下错误:

Error: Cannot cast from Fragment to SupportMapFragment 

sn-p如下:

GoogleMap mMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        mMap.addMarker(new MarkerOptions()
                .position(new LatLng(53.271900177, -9.04889965057))
                .title("GMI alway Location"));;

这是我引用它的 xml 声明:

<fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />

有人知道我哪里出错了吗?谢谢布赖恩 J

【问题讨论】:

    标签: android google-maps google-maps-markers supportmapfragment


    【解决方案1】:

    如果您在布局中使用SupportMapFragment,则必须使用SupportFragmentManagerFragmentActivity 类。

    所以使用getSupportFragmentManager() 方法而不是getFragmentManager()

    【讨论】:

    • 我尝试了上述修复,但出现此错误:'方法 getSupportFragmentManager() 未定义 MapGmit 类型'
    • 你的 Activity 扩展了 FramgnetActivity?
    • MapGmit 扩展了什么类?
    • MapGmit 扩展了 MapActivity,它是地图片段活动的 xaml 文件。
    • MapGmit 应该扩展 FramgnetActivity。
    猜你喜欢
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多