Ich möchte eine Android App erstellen, die Google Maps verwendet. Ich habe die Google Maps APIs Styling Wizard verwendet und die JSON-Datei erstellt. Welche Änderungen muss ich im Code meiner App (Android Studio) vornehmen, um Änderungen vorzunehmen?Styling einer Google Map
1
A
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 :)
Verwandte Themen
- 1. Google Map Theme Styling
- 2. Swift Map Styling mit GMS
- 3. Styling Google Charts Tabelle
- 4. Styling Google Maps API innen Akkordeon
- 5. Styling native Google Chrome Videosteuerungen
- 6. Google-Diagramm API-Styling-Tooltipps
- 7. Google Graph Table + Piechart Styling
- 8. Marker schwebt auf einer Google Map
- 9. Google Map Fragment in einer kreisförmigen Ansicht
- 10. Plotting ACF-Repeater auf einer Google Map
- 11. Deaktivierung der Tastaturnavigation in einer Google Map
- 12. Java Update Marker von einer Google Map
- 13. Anzeigen von Google Map in einer UIView
- 14. Diskrepanzen zwischen Google Map Search und Google Map API
- 15. Vollbild Google Map
- 16. Reagiere Google Map
- 17. Efficient Map Overlays in Android Google Map
- 18. Buildpfad mit Google Map
- 19. Google Map Zeichnung freihändig
- 20. Google Map in TabelleView
- 21. Polymer Google Map - Zeichenformen
- 22. Google map latLngBounds
- 23. Angular Google Map Integration
- 24. Google Map Einfache Polylinie Map to image
- 25. Google Map referer-not-allowed-map-Fehler
- 26. Google Map, Styling auf Marker img mit Klasse nicht funktioniert, aber mit img arbeiten [src]
- 27. Styling einer Tastennavigation
- 28. Google Map Marker Pulsanimation?
- 29. Google Map lesen Json
- 30. Codenameone google map