2016-10-19 4 views

Antwort

1

Nach Karte bereit, könnten Sie Stil Änderungen in OnMapReady

@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); 
} 

prüfen diese Links gilt: MapStyleOptions, GoogleSamples

2

einen benutzerdefinierten Stil zu google map Hinzufügen ist sehr einfach. Überprüfen Sie den folgenden Code.

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); 
     } 
    } 
} 

Erstellen Sie einen Ordnernamen roh unter res/Ordner. Kopieren Sie den JSON aus dem Google Maps API-Formatvorlagen-Assistenten in eine style_json-Datei, und fügen Sie ihn dem Raw-Ordner hinzu. Das ist es. Style wird angewendet. Überprüfen Sie diese example.

1

erstellen Sie innerhalb res/ ein Verzeichnis rohe. in rohem Sie eine Datei name.json erstellen und die json von Google Maps APIs Styling Wizard Inneren

im onMapReady (GoogleMap googleMap) Methode, dass Code setzen

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

und es ist alles setzen :)