这个函数是检查纬度还是经度在多边形内部还是外部。
func isAvalibleinsidePolygone{
let latitude = lat?.text
let longitude = lon?.text
if latitude != "" && longitude != "" {
// pathOfPolygon.removeAllCoordinates()
for p in places {
pathOfPolygon.add(p.coordinate)
}
ifGMSGeometryContainsLocation(CLLocationCoordinate2DMake(Double(latitude!)!, Double(longitude!)!), pathOfPolygon, true) {
alert(title:`enter code here` "YEAH!!!", msg: "You are inside the polygon")
} else {
alert(title: "OPPS!!!", msg: "You are outside the polygon")
}
}
}
但即使我想检查一个位置是否在多边形的"精度"范围内 - 例如,如果函数的精度为 30m,则距离多边形 30m 以内的任何位置仍应返回 true。所以参数会像纬度,经度,精度 例如:
func withinAccuracy(latitude:Double,longitude:Double,accuracy:Double){
//....
}
看看函数 GMSGeometryIsLocationOnPathTolerance(_ point: CLLocationCoordinate2D, _ path: GMSPath, _ geodesic: Bool, _ tolerance: CLLocationDistance) -> Bool
它完全可以满足您的需求。链接