Android Google Map set Style Map with json

i have develop a simple app and i have integrate a google map using this simple way:`

mapFragment.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {
            mClusterManager = new ClusterManager<Car2GoClusterItem>(getActivity(), map);

            map.setOnCameraChangeListener(mClusterManager);
            map.setInfoWindowAdapter(mClusterManager.getMarkerManager());
            map.setOnMarkerClickListener(mClusterManager);


            mClusterManager.setOnClusterItemClickListener(
                    new ClusterManager.OnClusterItemClickListener<Car2GoClusterItem>() {
                        @Override
                        public boolean onClusterItemClick(Car2GoClusterItem item) {
                            clickedClusterItem = item;
                            return false;
                        }
                    });

    });
}

public GoogleMap.OnCameraChangeListener getCameraChangeListener() {
    return new GoogleMap.OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition position) {
            Log.d("Zoom", "Zoom: " + position.zoom);

            if (previousZoomLevel <= 15 && position.zoom > 15) {
                map.clear();
                processMap(v, 16);
            }

            if (previousZoomLevel >= 15 && position.zoom < 15) {
                map.clear();
                processMap(v, 14);
            }

            previousZoomLevel = position.zoom;
        }
    };
}

public void processMap(View v, int zoom) {
    if (map == null) {
        map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map))
                .getMap();


    }

    if (map != null) {
    //// code here
    }
    }

Now i would like to set for my map a specific MapStyle by json and i have seen this code:

 public void onMapReady(GoogleMap googleMap) {

    // Customise the styling of the base map using a JSON object defined
    // in a string resource file. First create a MapStyleOptions object
    // from the JSON styles string, then pass this to the setMapStyle
    // method of the GoogleMap object.
    boolean success = googleMap.setMapStyle(new MapStyleOptions(getResources()
            .getString(R.string.style_json)));

    if (!success) {
        Log.e(TAG, "Style parsing failed.");
    }
    // Position the map's camera near Sydney, Australia.
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(-34, 151)));
}

but i don't know how to integrate because this sample is for activity instead i use a fragment and also when i tryto add this code give me a error. Any help? thanks


ANSWERS:


After a good research and code I implemented Google Map in fragment using the following code:

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.ArrayList;


public class MapFragment extends Fragment implements OnMapReadyCallback{


    public MapFragment() {
        // Required empty public constructor
    }

    private MapView mapView;
    private GoogleMap googleMap;
    View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_map, container, false);
        SupportMapFragment mapFragment = (SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mapView = (MapView) view.findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);
        mapView.onResume();
        mapView.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap map) {
        googleMap = map;

        googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
        googleMap.setMinZoomPreference(12.6f);
        googleMap.getUiSettings().setAllGesturesEnabled(true);
    }
}

Following is the xml code which I am using for map fragment

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <com.google.android.gms.maps.MapView
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.design.widget.CoordinatorLayout>

In this fragment you can volley can get JSON and style your map accordingly.



 MORE:


 ? How set language in Json of google map api?
 ? Google Map script syntax error
 ? Google Map script syntax error
 ? Google Map script syntax error
 ? Google maps api syntax error
 ? Google Maps distance server-side
 ? Google Maps distance server-side
 ? Google Maps distance server-side
 ? How to get distance from Google Map API from server side ASP.NET 2.0
 ? Pixel distance in Google Map (API V3) to avoid overlapping labels / overlays