代码之家  ›  专栏  ›  技术社区  ›  Vlad

谷歌地图风格-昼夜转换

  •  0
  • Vlad  · 技术社区  · 7 年前

    在谷歌的地图样式工具中,有没有一种简单的方法可以在“标准”和“夜间”之间创建中间样式: https://mapstyle.withgoogle.com/

    enter image description here

    单击“FINISH”将导出设置为JSON选项。

    enter image description here

    然后,我们将这个JSON复制到day(基于'standard'主题),然后重复这个过程以生成晚上的JSON。

    没有一种主题生成能力可以采用两种风格并给出“中间”风格。

    目的是让地图在晚上逐渐变暗,在早晨逐渐变亮。我们使用的是JSON输出,它可以手动更改-但是自动的方式会很好。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Martin Zeitler    7 年前

    你可以通过 JSON String 有了样式:

    @Override
    public void onMapReady(GoogleMap map) {
        try {
    
            /* the inital styles to be applied */
            String jsonString = this.getCurrentMapStyles();
    
            MapStyleOptions style = new MapStyleOptions(jsonString);
            boolean success = map.setMapStyle(style);
    
            if (! success) {Log.e(TAG, "Style parsing failed.");}
    
        } catch (Resources.NotFoundException e) {
            Log.e(LOG_TAG, "Can't find style. Error: ", e);
        }
    
        /* start an update interval timer ... */
    }
    
    /* the styles, according to the current time */
    private String getCurrentMapStyles() {
    
        long timestamp = System.currentTimeMillis() / 1000;
        String jsonString = "";
    
        /* styles to be generated, with some values mutated */
    
        return jsonString;
    }
    

    Style Reference