【问题标题】:Adding a marker to a Google maps fragment向 Google 地图片段添加标记
【发布时间】:2013-03-19 21:21:08
【问题描述】:

我已在我的应用程序中添加了一个地图片段,并添加了以下代码以在片段上放置一个标记。但我在代码 sn-p 中遇到错误。我已包含所有相关的导入。

错误是编译时的,如下:

1.MapFragment 无法解析为类型。

2.GoogleMap 无法解析为类型。

3.LatLng 无法解析为类型。

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        mMap.addMarker(new MarkerOptions()
                .position(new LatLng(0, 0))
                .title("Hello world"));

任何人都知道错误在 sn-p 中的位置吗?谢谢

【问题讨论】:

    标签: android google-maps-api-2 mapfragment


    【解决方案1】:

    我认为你应该先检查两件事

    1. Google Play 服务项目或库是否已添加到您的项目中?如果没有,请查看此链接http://developer.android.com/google/play-services/setup.html
    2. 如果你为android版本

               mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
      

    在最后一种情况下,您还需要将 XML 中使用的类更新为 class="com.google.android.gms.maps.SupportMapFragment"

    【讨论】:

    • Google Api Android 4.2.2 已导入我的项目,我认为其中包括播放服务?另外我已将相关代码添加到 Proguard 文件夹但仍无法识别。有什么建议吗?
    • “Google Api Android 4.2.2 已导入我的项目”没有任何意义:您的意思是您的项目符合 Google API 17,它对应于 Android 2.2.2。真正的问题是:您的测试设备上的 Android 版本是什么?无论如何,必须导入 Google Play 服务。为此,您需要在 Eclipse 中导入 Google Play 服务库,并从您的主项目中对其进行引用。
    猜你喜欢
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 2016-04-28
    • 1970-01-01
    相关资源
    最近更新 更多