2016-10-19 7 views

答えて

1

はマップ準備が完了したら、これらのリンクチェック

@Override 
public void onMapReady(GoogleMap map) { 
    mMap = map; 
    setMapStyle(); 
} 

private void setMapStyle() { 
    MapStyleOptions style = new MapStyleOptions("[" + 
      " {" + 
      " \"featureType\":\"poi.business\"," + 
      " \"elementType\":\"all\"," + 
      " \"stylers\":[" + 
      "  {" + 
      "  \"visibility\":\"off\"" + 
      "  }" + 
      " ]" + 
      " }," + 
      " {" + 
      " \"featureType\":\"transit\"," + 
      " \"elementType\":\"all\"," + 
      " \"stylers\":[" + 
      "  {" + 
      "  \"visibility\":\"off\"" + 
      "  }" + 
      " ]" + 
      " }" + 
      "]"); 

    mMap.setMapStyle(style); 
} 

OnMapReady

にスタイルの変更を適用できます。 MapStyleOptions、グーグルマップにカスタムスタイルを追加 GoogleSamples

2

は非常に簡単です。以下のコードを確認してください。

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 

    private GoogleMap mMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 
     // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
     SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
    } 


    @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(
          MapsActivity.this, R.raw.style_json)); 

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

res/folderの下にフォルダ名rawを作成します。 google maps apiスタイリングウィザードのjsonをコピーしてstyle_jsonファイルに貼り付け、生のフォルダに追加します。それでおしまい。スタイルが適用されます。これをチェックしてくださいexample

1

内に作成res/と呼ばれるディレクトリ。生でファイル・name.jsonを作成し、onMapReady(GoogleマップGoogleマップ)で

Google Maps APIs Styling WizardからJSONを置く方法は、そのコード

googleMap.setMapStyle(
       MapStyleOptions.loadRawResourceStyle(
         this, R.raw.name.json)); 

を入れて、それがすべてです:)