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.
In your custom Xamarin.Forms
GoogleMap renderer, you can set the style with the json content:
Xamarin.Android Example:
googleMap.SetMapStyle(MapStyleOptions.LoadRawResourceStyle(this, Resource.Raw.map_style_night));
Xamarin.iOS Example:
googleMapView.MapType = MapViewType.Normal; // Must be normal
var styleResource = NSBundle.MainBundle.GetUrlForResource("map_style_night", "json");
googleMapView.MapStyle = MapStyle.FromUrl(styleResource, null); // DO NOT pass an NSError, hard-crash / SIGSEGV
Note: Do not pass an NSError
instance to MapStyle.FromUrl
or MapStyle.FromJson
with the current Xamarin.Google.iOS.Maps binding (v2.1.0.2
) as this will cause a hard-crash (SIGSEGV
). I had to create a custom binding to allow NSError as an out
var in order to determine if the json is parsed correctly (also needed to the latest fixes in Google iOS Map v2.4.30121.0
as Xamarin is binding/bundling the older 2.1.0.2
version).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With