我正在尝试开发一个显示用户速度和其他数据的应用程序。
我想知道Core Location可以检测到的最低速度是多少。当我在街上移动时,它的读数是0.00。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
//i display some other data here
speedLbl.text =[NSString stringWithFormat:@"Speed: %f km/hr",([lastLocation speed]*3.6)];
}
答案 0 :(得分:4)
您应该设置distanceFilter
和desiredAccuracy
属性。
这是Jano的代码
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
/* Pinpoint our location with the following accuracy:
*
* kCLLocationAccuracyBestForNavigation highest + sensor data
* kCLLocationAccuracyBest highest
* kCLLocationAccuracyNearestTenMeters 10 meters
* kCLLocationAccuracyHundredMeters 100 meters
* kCLLocationAccuracyKilometer 1000 meters
* kCLLocationAccuracyThreeKilometers 3000 meters
*/
self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
/* Notify changes when device has moved x meters.
* Default value is kCLDistanceFilterNone: all movements are reported.
*/
self.locationManager.distanceFilter = 10.0f;
/* Notify heading changes when heading is > 5.
* Default value is kCLHeadingFilterNone: all movements are reported.
*/
self.locationManager.headingFilter = 5;
// update location
if ([CLLocationManager locationServicesEnabled]){
[self.locationManager startUpdatingLocation];
}
速度计算:
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
double speed = newLocation.speed;
//another way
if(oldLocation != nil)
{
CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation];
NSTimeInterval sinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
speed = distanceChange/sinceLastUpdate;
}
}
答案 1 :(得分:1)
@Osama Khalifa,这取决于您使用location manager
的方式。
对于speed
计算,我希望您使用satellite GPS (stopUpdatingLocation
)而不是GPS
到mobile network
(startMonitoringSignificantLocationChanges)
,因为GPS
通过移动塔不会{39}在accuracy
中有speed
。
此外,您需要将desiredAccuracy
和distanceFilter
值设置为最接近的值,以获得更多accurate
值。
Note : more accurate results you ask consume more of iPhone battery power.
答案 2 :(得分:0)
我相信没有限制。你必须自己计算速度:
distanceChange * timeSpan
distanceChange = [newLocation getDistanceFrom:oldLocation]
timeSpan = time when retrieved new Location - time when retrieved old Location
看一下this帖子!