如何确定从用户位置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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...