如何解决如何确定从用户位置CLLocationCoordinate2D到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))
path.addLine(to: CGPoint(x: 32.7915926,y: -96.8016962))
}
我从这篇文章中看到了此功能以进行命中测试:how-to-get-the-distance-to-a-cgpath-for-hit-testing
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
}
似乎有用的功能,唯一的问题是对于参数,您必须输入特定的距离。我们试图做的是找到到CGPath的距离。这样的东西甚至可以在Swift中获得吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。