有谁知道如何在Xamarin android上使用样式化的Google地图?Google最近添加了从此处https://mapstyle.withgoogle.com/创建样式地图的功能,并且它们显示了如何使用样式地图的示例
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);
无论如何,在Xamarin Android中可以做到这一点吗?
随着Xamarin的发布,Google Play地图服务v 32.961.0 https://www.nuget.org/packages/Xamarin.GooglePlayServices.Maps/现在支持MapStyleOptions。
要使用样式化的地图,请创建一个新的MapStyleOptions对象
private void setSelectedStyle()
{
MapStyleOptions style;
style = new MapStyleOptions("[" +
" {" +
" \"elementType\":\"geometry\"," +
" \"stylers\":[" +
" {" +
" \"color\":\"#242f3e\"" +
" }" +
" ]" +
" }," +
" {" +
" \"featureType\":\"transit\"," +
" \"elementType\":\"geometry\"," +
" \"stylers\":[" +
" {" +
" \"color\":\"#2f3948\"" +
" }" +
" ]" +
" }" +
"]");
map.SetMapStyle(style);
}
然后在OnMapReady中调用它
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句