Find the closest latitude and longitude

前端 未结 3 1653
情深已故
情深已故 2020-12-08 03:05

I\'m writing a small program and to improve efficiency, I need to be able to find the closest latitude and longitude in my array.

Assume you have the following code:

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 03:51

    Also u can simple do:

    import mpu
    def distance(point1, point2):
        return mpu.haversine_distance(point1, point2)
    
    def closest(data, this_point):
        return min(data, key=lambda x: distance(this_point, x))
    

提交回复
热议问题