Issue
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.
Solution
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).
Answered By - SushiHangover

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.