在Xamarin Android上使用样式化的Google地图

梅尔·斯奈德(Meir Snyder)

有谁知道如何在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中可以做到这一点吗?

梅尔·斯奈德(Meir Snyder)

随着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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Xamarin Android上使用Google Maps

来自分类Dev

在Xamarin Android上使用Google Maps

来自分类Dev

xamarin android alignParentRight 样式

来自分类Dev

Google地图未显示-Xamarin

来自分类Dev

设置Android视图的样式-Xamarin

来自分类Dev

Xamarin表单-Android中的样式

来自分类Dev

Xamarin Android上的振动

来自分类Dev

在Xamarin(Visual Studio)中为Android刷卡,例如在地图/新闻中使用Google卡

来自分类Dev

添加 Google 地图时 Xamarin Android 构建出错

来自分类Dev

Xamarin XAML条件样式

来自分类Dev

Xamarin:TabWidget样式

来自分类Dev

Xamarin按钮样式

来自分类Dev

Xamarin Google地图不起作用

来自分类Dev

Xamarin和Google地图上的距离不同

来自分类Dev

无法设置Xamarin Android CalendarView的样式

来自分类Dev

使用 Fontawesome 图标化 Xamarin

来自分类Dev

Xamarin.Forms或Xamarin.Android/Xamarin.IOS

来自分类Dev

Xamarin表单-地图-可以通过按钮调用Google地图吗?

来自分类Dev

在Windows上卸载Xamarin

来自分类Dev

Xamarin上的黑屏

来自分类Dev

Xamarin + Parse上的分析

来自分类Dev

Xamarin.Android与Android

来自分类Dev

搭配Android使用Xamarin Studio上的AdMob,Google Play服务不存在

来自分类Dev

Xamarin Forms-Xamarin Forms导航栏在Android上滚动

来自分类Dev

Xamarin表格Google登录

来自分类Dev

Google AdMobs Xamarin CrossPlatform

来自分类Dev

Android Xamarin:无法使用ActionBarActivity

来自分类Dev

Xamarin表单的BackDoor(Android)

来自分类Dev

降级Xamarin.Android