如何使用iPhone的GPS获取汽车的速度 [英] How to get car's speed with gps for iphone

查看:239
本文介绍了如何使用iPhone的GPS获取汽车的速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我开发了用于iPhone的gps来提高汽车的速度,并对其进行了多次测试.
然后我没有准确的速度,通常将其设置为0.

我的代码如下.

Hello, Everybody.

I developed to get speed of car with gps for iphone and tested it many times.
then i didn''t have accurate speed and it often was set 0.

My code is below.

- (void) setupLocationManager
{
    self.locationManager = [[[CLLocationManager alloc] init] autorelease];
    if (locationManager.locationServicesEnabled == NO) {
        UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [servicesDisabledAlert show];
        [servicesDisabledAlert release];
    }

    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
    self.stateString = NSLocalizedString(@"Updating", @"Updating");
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
	
    // test that the horizontal accuracy does not indicate an invalid measurement
 	if (newLocation.horizontalAccuracy < 0) return;

	// test the age of the location measurement to determine if the measurement is cached
    // in most cases you will not want to rely on cached measurements
	NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0) return;
	
	if ([newLocation speed] < 0.0f) {
[g_Config SetSpeed:0];
[g_Config SetCourseValue];
	}
	else {
		float fSpeed = [newLocation speed];
		[g_Config SetRealSpeed:fSpeed];
		[g_Config SetCourseValue:newLocation.course];
	}
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{
	NSLog(@"didFailWithError");
[g_Cofig SetSpeed:0];
[g_Config SetCourseValue:0];
	
    // The location "unknown" error simply means the manager is currently unable to get the location.
    // We can ignore this error for the scenario of getting a single location fix, because we already have a 
    // timeout that will stop the location manager to save power.
    if ([error code] != kCLErrorLocationUnknown) {
        [self stopUpdatingLocation:NSLocalizedString(@"Error", @"Error")];
    }
}

- (void)stopUpdatingLocation:(NSString *)state {
	self.stateString = state;
	NSLog(@"%@", state);
    [locationManager stopUpdatingLocation];
	locationManager.delegate = nil;
}



请帮帮我.

如果我从汽车上获得正确的速度,如何设置distanceFilter和期望的准确度?

谢谢.



Please help me.

If i get correct speed from car, how to set distanceFilter and desiredAccuracy?

thanks .

推荐答案

首先,民用GPS系统不够精确,无法可靠地计算出准确的速度.还有很多因素会干扰信号,有时甚至使用蜂窝塔三角测量而不是真正的GPS.

其次,如果您在开车中并且需要准确的速度计算,那么已经有一个应用程序可以用于此.它被称为车速表,并已预装在大多数车辆上.

第三,并不是所有内容都需要iPhone应用程序.
First off, civilian GPS systems are not accurate enough to be used to reliably calculate an accurate speed. There are also a number of factors that can interfere with the signals, sometimes you are even using cell tower triangulation rather than true GPS.

Secondly, if you are in a car and need accurate speed calculations there is already an app for that. It''s called the speedometer and comes preloaded on most vehicles.

Third, not everything requires an iPhone app.


这篇关于如何使用iPhone的GPS获取汽车的速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆