>有谁知道如何在Xamarin android上使用样式化的谷歌地图?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 中调用它