在 android 地图 v2 中创建自定义样式地图时无法解析 setMapStyle()

Cant resolve setMapStyle() while creating custom styled map in android map v2

我试图在我的应用程序的地图中实现自定义配色方案。所以我按照 google 的指示在 onMapReady() 函数中调用了自定义 JSON(JSON 是使用 google 提供的工具创建的)。我的 onMapready 函数如下所示

  @Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
               try {
            // Customise the styling of the base map using a JSON object defined
            // in a raw resource file.
            boolean success = mMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(
                            this, R.raw.style_json));

            if (!success) {
                Log.e("MapsActivityRaw", "Style parsing failed.");
            }
        } catch (Resources.NotFoundException e) {
            Log.e("MapsActivityRaw", "Can't find style.", e);
        }
    }

但无论我尝试什么,它都显示函数 setMapStyle() 中存在错误。

我是 android 编程的初学者,所以如果它是一种明显的小解决方案,请提供帮助。我已经搜索了很多以获得解决方案。

提前致谢

如@MD 所说,您需要更新 build.gradle 才能使用 Play Services 的最新版本。当前版本是 9.6.1

dependencies {
    compile 'com.google.android.gms:play-services:9.6.1'
}

更新 build.gradle 后,您将能够设置地图样式,但请注意,正如 the documentation 所说,样式仅适用于法线地图类型。

无法解析 googleMap.setMapStyle() FIXED

更新所有Google播放服务库到9.8.0解决我的问题

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-messaging:9.8.0'
    compile 'com.google.android.gms:play-services-maps:9.8.0'
    compile 'com.google.android.gms:play-services-location:9.8.0'
    compile 'com.google.firebase:firebase-database:9.8.0'
    compile 'com.google.firebase:firebase-auth:9.8.0'
    compile 'com.google.firebase:firebase-crash:9.8.0'
    compile 'com.google.maps.android:android-maps-utils:0.4.4'
    compile 'com.google.android.gms:play-services-appindexing:9.8.0'

}

apply plugin: 'com.google.gms.google-services'