gpt4 book ai didi

ios - 如何在不同的郊区覆盖带有彩色的 ta GMSMapView?

转载 作者:搜寻专家 更新时间:2023-10-31 22:42:59 25 4
gpt4 key购买 nike

我正在使用 Swift 构建一个应用程序。我已经使用以下代码成功地将谷歌地图添加到我的应用程序作为我的主视图 Controller 上的 subview :

let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
var mapView = GMSMapView.map(withFrame: CGRect(x: screenWidth*0.03, y: 245, width: screenWidth*0.94, height: screenHeight*0.45), camera: camera)
self.view.addSubview(mapView)

我现在想做一些听起来有点棘手的事情,但我确信这是可能的。我希望能够覆盖我的 mapView 中 map 的不同区域,这些区域由名称或邮政编码指定,具有不同的可点击颜色。这似乎是使 map 变得漂亮的常用方法,而且我相信有一个现有的解决方案可以轻松做到这一点。我应该怎么做?

最佳答案

我找到了一个方法来做到这一点! Google Maps API 提供!一旦你像我原来的问题一样设置了你的 map ,你就可以这样做来向 map 添加一个圆圈:

let circleCenter = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
let circ = GMSCircle(position: circleCenter, radius: 2000)
circ.fillColor = UIColor.green.withAlphaComponent(0.5)
circ.map = mapView

您还可以绘制更复杂的形状,包括一系列纬度/经度,如下所示:

let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.886080, longitude: -122.137585))
rect.add(CLLocationCoordinate2D(latitude: 37.899356, longitude: -122.130203))
rect.add(CLLocationCoordinate2D(latitude: 37.900101, longitude: -122.104282))
rect.add(CLLocationCoordinate2D(latitude: 37.879644, longitude: -122.101192))
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor.flatWatermelonDark.withAlphaComponent(0.5)
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.isTappable = true
polygon.map = mapView

我仍然没有想出一种无缝的方式来覆盖任何邮政编码,但这可以通过查找/估计邮政编码区域的纬度/经度边缘,使用上述代码片段手动完成。

关于ios - 如何在不同的郊区覆盖带有彩色的 ta GMSMapView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43291841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com