首页 > 解决方案 > 如何在谷歌地图 Swift API 中实现颜色渐变?

问题描述

我想显示具有从绿色到红色的不同强度的数据点(Google Maps Swift)。地图上数据点的面积应保持不变。GMUWeightedLatLng 类将坐标作为参数以及强度。然而,后者表示该特定点的区域,它不会改变颜色。

let coords = GMUWeightedLatLng(coordinate: CLLocationCoordinate2DMake(latitude, longitude), intensity: 1)

heatmapLayer.weightedData.append(coords)

heatmapLayer.gradient 提供了更改渐变的可能性,但它使所有数据点都相同,而我希望每个点都显示从绿色到红色的自定义阴影,具有相同的区域。

let gradientColors: [UIColor] = [.green, .red]
heatmapLayer.gradient = GMUGradient(
            colors: gradientColors,
            startPoints: gradientStartPoints,
            colorMapSize: 256)

我将非常感谢任何帮助!

标签: iosswiftgoogle-maps

解决方案


推荐阅读