Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 3/不带CGPath或Mapview的MKPolygon内的当前位置_Swift_Core Location_Mkpolygon - Fatal编程技术网

Swift 3/不带CGPath或Mapview的MKPolygon内的当前位置

Swift 3/不带CGPath或Mapview的MKPolygon内的当前位置,swift,core-location,mkpolygon,Swift,Core Location,Mkpolygon,完全披露-我是新来的,但我已经挖掘了所有东西,似乎无法解析我需要的东西。我已经到了谷歌只返回紫色链接的地步 是否有一种方法可以在不操作MapView的情况下对照多个MKPolygon检查用户当前的CLLocation lat/lon?基本上只是在背景中,直到lat/lon在MKPolygon内,然后返回BOOL 这是我目前拥有的 var points: [CLLocationCoordinate2D] = [CLLocationCoordinate2D]() points.ap

完全披露-我是新来的,但我已经挖掘了所有东西,似乎无法解析我需要的东西。我已经到了谷歌只返回紫色链接的地步

是否有一种方法可以在不操作MapView的情况下对照多个MKPolygon检查用户当前的CLLocation lat/lon?基本上只是在背景中,直到lat/lon在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)
    }

我建议从这里开始: