How to find out distance between coordinates?

前端 未结 10 1308
猫巷女王i
猫巷女王i 2020-12-12 15:23

I want to make it so that it will show the amount of distance between two CLLocation coordinates. Is there someway to do this without a complex math formula? If there isn\'t

10条回答
  •  悲哀的现实
    2020-12-12 16:13

    For objective-c

    You can use distanceFromLocation to find the distance between two coordinates.

    Code Snippets:

    CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:lng1];
    
    CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:lng2];
    
    CLLocationDistance distance = [loc1 distanceFromLocation:loc2];
    

    Your output will come in meters.

提交回复
热议问题