2017-02-01 3 views
0

Kann jemand gestylte Google Maps mit Xamarin Android verwenden? Google die Möglichkeit, vor kurzem hinzugefügt von hier aus einem Stil Karte zu erstellen https://mapstyle.withgoogle.com/ und sie zeigen eine Probe, wie es dort ohnehinVerwenden von gestylten Google Maps mit Xamarin Android

private void setSelectedStyle() { 
    MapStyleOptions style; 
    switch (mSelectedStyleId) { 
     case R.string.style_label_retro: 
      // Sets the retro style via raw resource JSON. 
      style = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_retro); 
      break; 
     case R.string.style_label_night: 
      // Sets the night style via raw resource JSON. 
      style = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_night); 
      break; 
     case R.string.style_label_grayscale: 
      // Sets the grayscale style via raw resource JSON. 
      style = MapStyleOptions.loadRawResourceStyle(this, R.raw.mapstyle_grayscale); 
      break; 
     case R.string.style_label_no_pois_no_transit: 
      // Sets the no POIs or transit style via JSON string. 
      style = new MapStyleOptions("[" + 
        " {" + 
        " \"featureType\":\"poi.business\"," + 
        " \"elementType\":\"all\"," + 
        " \"stylers\":[" + 
        "  {" + 
        "  \"visibility\":\"off\"" + 
        "  }" + 
        " ]" + 
        " }," + 
        " {" + 
        " \"featureType\":\"transit\"," + 
        " \"elementType\":\"all\"," + 
        " \"stylers\":[" + 
        "  {" + 
        "  \"visibility\":\"off\"" + 
        "  }" + 
        " ]" + 
        " }" + 
        "]"); 
      break; 
     case R.string.style_label_default: 
      // Removes previously set style, by setting it to null. 
      style = null; 
      break; 
     default: 
      return; 
    } 
    mMap.setMapStyle(style); 

Ist zu verwenden, um dies in Xamarin Android zu tun?

Antwort

1

Mit der Veröffentlichung der Xamarin Google Play Map-Dienste v 32.961.0 https://www.nuget.org/packages/Xamarin.GooglePlayServices.Maps/ wird jetzt die MapStyleOptions unterstützt.

Um einen Stil Karte erstellen Sie ein neues Objekt MapStyleOptions

private void setSelectedStyle() 
    { 
     MapStyleOptions style; 
     style = new MapStyleOptions("[" + 
        " {" + 
        " \"elementType\":\"geometry\"," + 
        " \"stylers\":[" + 
        "  {" + 
        "  \"color\":\"#242f3e\"" + 
        "  }" + 
        " ]" + 
        " }," + 
        " {" + 
        " \"featureType\":\"transit\"," + 
        " \"elementType\":\"geometry\"," + 
        " \"stylers\":[" + 
        "  {" + 
        "  \"color\":\"#2f3948\"" + 
        "  }" + 
        " ]" + 
        " }" + 
        "]"); 
     map.SetMapStyle(style); 
    } 

zu verwenden und es dann in OnMapReady nennen

Verwandte Themen