Reputation: 819
Does anyone know how to use styled google maps with Xamarin android? Google recently added the ability to create a styled map from here https://mapstyle.withgoogle.com/ and they show a sample of how to use it
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);
Is there anyway to do this in Xamarin Android?
Upvotes: 0
Views: 887
Reputation: 819
With the release of the Xamarin google play map services v 32.961.0 https://www.nuget.org/packages/Xamarin.GooglePlayServices.Maps/ the MapStyleOptions is now supported.
To use a styled map create a new MapStyleOptions object
private void setSelectedStyle()
{
MapStyleOptions style;
style = new MapStyleOptions("[" +
" {" +
" \"elementType\":\"geometry\"," +
" \"stylers\":[" +
" {" +
" \"color\":\"#242f3e\"" +
" }" +
" ]" +
" }," +
" {" +
" \"featureType\":\"transit\"," +
" \"elementType\":\"geometry\"," +
" \"stylers\":[" +
" {" +
" \"color\":\"#2f3948\"" +
" }" +
" ]" +
" }" +
"]");
map.SetMapStyle(style);
}
and then call it in OnMapReady
Upvotes: 3