android - google mapView 样式不适用于 maptype=TERRAIN 的 Android

标签 android google-maps android-mapview styling android-maps-v2

使用这个 stackoverflow question ,我尝试将一些自定义样式应用于 Android map View 。

造型基本上就是把水弄黑

mapstyle_json.js:

[
    {
        featureType: 'water',
        elementType: 'geometry',
        stylers: [{color: '#000000'}]
      },
      {
        featureType: 'water',
        elementType: 'labels.text.fill',
        stylers: [{color: '#515c6d'}]
      },
      {
        featureType: 'water',
        elementType: 'labels.text.stroke',
        stylers: [{color: '#17263c'}]
      }
]

我的主要 Activity :

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final MapView mapView = (MapView) findViewById(R.id.mapView);
        final android.content.Context context = this;

        mapView.onCreate(savedInstanceState);
        mapView.getMapAsync(new OnMapReadyCallback() {

            @Override
            public void onMapReady(GoogleMap googleMap) {
                googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); // Without this line, the styling works as intended
                try {
                    // Customise the styling of the base map using a JSON object defined
                    // in a raw resource file.
                    boolean success = googleMap.setMapStyle(
                            MapStyleOptions.loadRawResourceStyle(
                                    context, R.raw.mapstyle_json));

                    if (!success) {
                        Log.e("1", "Style parsing failed.");
                    }
                } catch (Resources.NotFoundException e) {
                    Log.e("1", "Can't find style. Error: ", e);
                }
                Log.d("1", "onMapReady: something");
                LatLng coordinates = new LatLng(45.832119, 6.865575);
                googleMap.addMarker(new MarkerOptions().position(coordinates).title("hello"));
                googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates, 12));
                mapView.onResume();
            }
        });
    } 
}

在不设置 map 类型(使用默认 map 类型)的情况下,样式会正常工作。考虑到链接问题,应该可以设置 TERRAIN 类型 map 的样式。 (也许只使用 javascript)。

为什么这种样式没有应用于地形类型 map ?在 Android mapView 中可以吗?

编辑:

代码基于谷歌自己的指南,原始资源用例:https://developers.google.com/maps/documentation/android-sdk/styling

也许这是一个 google API v2 与 v3 的问题。据我了解,Android 使用 API v2。链接的问题是关于 v3

最佳答案

似乎是它的预期行为。来自 Official Documentation :

Styling works only on the normal map type.

Normal map type是:

Typical road map. Shows roads, some features built by humans, and important natural features like rivers. Road and feature labels are also visible.

关于android - google mapView 样式不适用于 maptype=TERRAIN 的 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53820851/

相关文章:

android - 在 Android 的 MapView 上缓存正在绘制的内容

android - 如何区分未接来电和拒绝接听?

android - 如何 : View placeholder for embedded activities

ios - 如何在后台快速跟踪用户位置

google-maps - 如何从 Google map 应用程序返回到我的应用程序?

android - 如何在Android中一键删除 map View 中的所有标记?

android - MapView.onMapReady 从未在 Fragment 中调用以在 MapView 中加载 Google map

android - 带有边距/填充的 ListView 滚动条样式

android - gson.fromjson 返回 null

android - 如何在 onCreateView() 中调用 SupportPlaceAutocompleteFragment