2

全面披露-我是新来的,但我已经挖掘了所有内容,似乎无法将我需要的东西解析在一起。我正处于谷歌只返回紫色链接的地步。

有没有办法在不操作 MapView 的情况下根据几个 MKPolygon 检查用户当前的 CLLocation 纬度/经度?基本上只是在后台,直到纬度/经度在 MKPolygon 内,然后返回一个 BOOL。

这是我目前所拥有的。

var points: [CLLocationCoordinate2D] = [CLLocationCoordinate2D]()

        points.append(CLLocationCoordinate2DMake(43.8138, -78.8884))
        points.append(CLLocationCoordinate2DMake(43.8074, -78.8768))
        points.append(CLLocationCoordinate2DMake(43.8130, -78.8688))
        points.append(CLLocationCoordinate2DMake(43.8210, -78.8806))

    let zoneA: MKPolygon = MKPolygon(coordinates: &points, count: 4)

    let point1 = CLLocationCoordinate2D(latitude: 43.8146, longitude: -78.8784)


    func contained(by vertices: [CLLocationCoordinate2D]) -> Bool {

        let path = CGMutablePath()

        for vertex in vertices {

            if path.isEmpty
            {
                path.move(to: CGPoint(x: vertex.longitude, y: vertex.latitude))
            }
            else
            {
                path.addLine(to: CGPoint(x: vertex.longitude, y: vertex.latitude))
            }
        }

        let point = CGPoint(x: 43.7146, y: -78.8784)

        return path.contains(point)
    }
4

0 回答 0