【问题标题】:Marker tint makes it too dark on Google Maps iOS标记色调使其在 Google 地图 iOS 上太暗
【发布时间】:2020-12-04 07:56:43
【问题描述】:

当我创建一个标记并将其添加到地图(使用 Google 地图)时,与 Android 相比,它的色调使其太暗。

这是它的外观:

在 Android 上看起来还不错:

两者使用相同的颜色。

这里是完整的 iOS 代码:

import UIKit
import GoogleMaps
import MapKit

class ViewController: UIViewController {

    @IBOutlet weak var mapView: GMSMapView!
    let color = UIColor(red: 254 / 255.0, green: 247 / 255.0, blue: 120 / 255.0, alpha: 1)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        mapView.animate(to: GMSCameraPosition(latitude: 53.141214, longitude: 17.957853, zoom: 15))
        addRoute()
        addMarker()
    }
    
    func addRoute() {
        let path = GMSMutablePath()
        path.add(CLLocationCoordinate2D(latitude: 53.141546, longitude: 17.955096))
        path.add(CLLocationCoordinate2D(latitude: 53.141088, longitude: 17.958740))
        let polyline = GMSPolyline(path: path)
        polyline.strokeColor = color
        polyline.strokeWidth = 5
        polyline.map = mapView
    }
    
    func addMarker() {
        let marker = GMSMarker()
        marker.position = CLLocationCoordinate2D(latitude: 53.141214, longitude: 17.957853)
        marker.icon = GMSMarker.markerImage(with: color)
        marker.map = mapView
    }

}

为了使这个答案完整且易于测试,我提供了您可以测试的示例项目:

https://drive.google.com/file/d/1StUxLzPldMhcMX4dmuGfy89Bbv9h5Cus/view?usp=sharing

唯一需要做的就是用你的替换 google maps api 密钥。

编辑:

我知道我可以使用自定义图像。我想使用默认标记图像并找到修改颜色以匹配 Android 外观的方法。

【问题讨论】:

  • Google Maps SDK for iOS 与 Google Maps SDK for Android 不同。有差异是很自然的。如果您需要相同的图像,请自己创建相同的图像并使用它。
  • 我知道这是 2 个独立的 SDK,但几乎相似。我想提供相同的体验,因此需要相同的图像。 Tint 在 iOS 上的效果可能有所不同,但应该有一种方法可以修改颜色以匹配 android 的外观。
  • 您可能需要在Google Issue Tracker 中添加一个条目,以检查这是否是 SDK 的问题。

标签: android ios swift google-maps


【解决方案1】:

定义颜色如下行..我不知道它是否会解决您的问题。但就我而言,它起作用了(有趣的方式)。

 let color = UIColor(red: 254.0/255.0, green: 247.0/255.0, blue: 120.0/ 255.0, alpha: 1)

【讨论】:

  • 这与我提供的几乎相同。唯一的区别是数字后面的“.0”(除法之前),这并不重要,因为浮动除法由第二个数字(255.0)保证。
  • 我不知道为什么,但在我的情况下它起作用了。连我都惊呆了。你可以试试。
  • 刚试过。 254 或 254.0 没有区别
猜你喜欢
  • 2013-03-27
  • 2021-11-20
  • 1970-01-01
  • 2014-03-22
  • 2011-11-23
  • 2018-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多