Use custom map style in Xamarin Forms?

Viewed 1963

I have successfully implemented Google Maps into my Xamarin Forms project but now I want to change its style. I want to use a style from SnazzyMaps but I don't know how to do that. I have read on the forums that you can load the json from SnazzyMaps into the application but I have no idea how to do that.

2 Answers

Xaml:

     <StackLayout VerticalOptions="FillAndExpand" Padding="1,10,0,0">
            <maps:Map        
                x:Name="MyMap" 
                IsShowingUser="true"/>
        </StackLayout>

I call this from code behind:

var assembly = typeof(MapPage).GetTypeInfo().Assembly;
            Stream stream = assembly.GetManifestResourceStream("MyApp.Helpers.Style.json");
            string Json = "";
            using (var reader = new StreamReader(stream))
            {
                Json = reader.ReadToEnd();
            }
            MyMap.MapStyle = MapStyle.FromJson(Json);

Dont forget to put the .json as Embedded Resource.

Related