Distance to a location while user is in motion

后端 未结 1 995
说谎
说谎 2020-12-18 11:18

I\'m in the process of writing an application that shows the user\'s distance from a fixed point as the user walks around (i.e. the label showing the distance from the user

相关标签:
1条回答
  • 2020-12-18 11:53

    Are you filtering out old (cached) positions? You should also filter based on accuracy, you probably don't want low accuracy locations.

    You won't get continous or periodic update, the callback only occurs when the location has changed.

    Assuming the device has GPS and can see enough GPS satellites to get a good position, this works fine.

    -(void)locationManager:(CLLocationManager *)manager 
       didUpdateToLocation:(CLLocation *)newLocation 
              fromLocation:(CLLocation *)oldLocation {
    
        NSTimeInterval age = -[newLocation.timestamp timeIntervalSinceNow]; 
    
        if (age > 120) return;    // ignore old (cached) updates
    
        if (newLocation.horizontalAccuracy < 0) return;   // ignore invalid udpates
    
        ...
    }
    
    0 讨论(0)
提交回复
热议问题