iPhone: Sorting based on location

前端 未结 5 1708
天命终不由人
天命终不由人 2020-12-14 13:37

I have been working on an iPhone app, where-in i have list of users in a NSMutableArray like below.

myMutableArray: (
    {
        FirstName = Getsy;
               


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 14:19

    First thing, you will need to calculate the distance between your current location and the location of each other user.

    Talking mathematically, here is a Wolfram|Alpha example

    Now "programmatic-ally", you can use CLLocation class, here is an example:

    (CLLocationDistance)getDistanceFrom:(const CLLocation *)location
    

    But first you will need to create the location object from your Latitude and Longitude. You can use:

    (id)initWithLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude
    

提交回复
热议问题