Ios 如何确定与用户的距离';s位置(CLLocationCoordinate2D)到CGPath?
我们绘制了一些CGPATH,根据用户的坐标,我们试图找到离用户最近的路径。以下是绘制路径的方式:Ios 如何确定与用户的距离';s位置(CLLocationCoordinate2D)到CGPath?,ios,swift,mapkit,core-location,cgpath,Ios,Swift,Mapkit,Core Location,Cgpath,我们绘制了一些CGPATH,根据用户的坐标,我们试图找到离用户最近的路径。以下是绘制路径的方式: func createPath(){ path.move(to: CGPoint(x: 32.7915055, y: -96.8028408)) path.addLine(to: CGPoint(x: 32.7919914, y: -96.8022031)) path.addLine(to: CGPoint(x: 32.7910108, y: -96.8025008))
func createPath(){
path.move(to: CGPoint(x: 32.7915055, y: -96.8028408))
path.addLine(to: CGPoint(x: 32.7919914, y: -96.8022031))
path.addLine(to: CGPoint(x: 32.7910108, y: -96.8025008))
path.addLine(to: CGPoint(x: 32.7915926, y: -96.8016962))
}
我在点击测试的帖子中看到了这个函数:
这似乎是一个有用的函数,唯一的问题是,对于参数,您必须输入一个特定的距离。我们要做的是找到到CGPath的距离。在Swift中是否可以获得类似的结果?距离变量似乎与线条的宽度有关,而不是与线条的距离有关。一个奇怪的命名约定是肯定的,但是一条非常粗的线会产生一个不同于细线的结果-
func isPoint(point: CGPoint, withinDistance distance: CGFloat, ofPath path: CGPath) -> Bool {
if let hitPath = CGPath( __byStroking: path,
transform: nil,
lineWidth: distance,
lineCap: CGLineCap.round,
lineJoin: CGLineJoin.miter,
miterLimit: 0) {
let isWithinDistance = hitPath.contains(point)
return isWithinDistance
}
return false
}