2017-08-10 146 views

回答

3

在您的自定義Xamarin.Forms GoogleMap的渲染器,你可以設置樣式與JSON內容:

Xamarin.Android例子:

googleMap.SetMapStyle(MapStyleOptions.LoadRawResourceStyle(this, Resource.Raw.map_style_night)); 

Xamarin.iOS例子:

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 

:做不是通過一個NSError instan ce到MapStyle.FromUrlMapStyle.FromJson與當前的Xamarin.Google.iOS.Maps綁定(v2.1.0.2),因爲這將導致硬件崩潰(SIGSEGV)。我不得不創建一個自定義綁定,以允許NSError作爲out var,以確定json是否被正確解析(對於Xamarin綁定/捆綁舊版2.1.0.2版本,也需要Google iOS的最新修補程序v2.4.30121.0)。

enter image description here

+0

我沒有「SetMapStyle」的方法 – Radu

+0

@Radu'SetMapStyle'是在*本地* Android的GoogleMap的類中的方法,你需要一個定製的渲染器中使用它。 – SushiHangover

+0

這就是我想要做的。我也嘗試更新所有nuget包,但該方法仍然不起作用 – Radu

相關問題