ios - GMSMapView 中的倒多边形

标签 ios iphone objective-c google-maps-sdk-ios

我必须为我的 iPhone 项目使用 Google map ,我正在使用 GMSPolygon 绘制多边形,但我如何填充 map 上除多边形内部以外的所有地方。就像下图一样。

谢谢。

sample

最佳答案

我试过你的问题。主要想法是用多边形填充整个地球,然后为您的特定区域打洞。这是示例代码,但问题是我无法创建多边形来覆盖整个地球。第一种方法是为每个季度创建 4 个多边形。

PGeoCountry 是一个在 boundariesPaths:[GMSPath] 中具有所需区域的结构

func locateCountry(country: PGeoCountry) {
    // 1. Create one quarter earth filling polygon
    let fillingPath = GMSMutablePath()
    fillingPath.addLatitude(90.0, longitude: -90.0)
    fillingPath.addLatitude(90.0, longitude: 90.0)
    fillingPath.addLatitude(0, longitude: 90.0)
    fillingPath.addLatitude(0, longitude: -90.0)

    let fillingPolygon = GMSPolygon(path:fillingPath)
    let fillColor = UIColor(red: 0.6, green: 0.6, blue: 0.6, alpha: 0.6)
    fillingPolygon.fillColor = fillColor
    fillingPolygon.map = self.mapView

    // 2. Add prepared array of GMSPath
    fillingPolygon.holes = country.boundariesPaths

    // 3. Add lines for boundaries
    for path in country.boundariesPaths {
        let line = GMSPolyline(path: path)
        line.map = self.mapView
        line.strokeColor = UIColor.blackColor()
    }

}

结果如下:

enter image description here

关于ios - GMSMapView 中的倒多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20772500/

相关文章:

ios - 动画雷达叠加 MKMapView iOS

iphone - 在 iOS 6 UIWebview 组件中显示智能横幅

iphone - 如何在 safari、chrome 或 firefox 等桌面浏览器上测试适用于 iPhone 的条件 CSS?

iphone - Xcode 4.3.2 中的声音问题

ios - 如何从 Objective C 类访问 swift 类的 List 属性

objective-c - 带有 popViewController 的 backBarButtonItem 和滑动

ios - 在自定义类下拉 Xcode 8.3.2 中找不到自定义 Controller 类

ios - 使用 Autolayout 和/或 preferredFontForTextStyle 时,UITextview 被随机剪裁

ios - 手动验证 TLS 证书(ios Objective-c)

iOS 6.0 : UISplitViewController Popover broken or design changed by Apple?