我正在研究侧重于建筑物(校园)中的行人的iOS应用程序。我已经开发了一个足够好的(我相信)用户的位置更新,但是,我希望任何人比我更专家给我一些提示,建议准确的位置,电池的问题等。此外,是否有可能停止位置更新和n秒后再次启动?是我为了节约能源而做的一个想法。目前,应用程序正在检测当前位置,但蓝点(用户)仍在移动,我不喜欢这样。有什么可以做的?用户的位置和电池消耗
下面是我的didUpdateToLocation方法:从一个文件中(存储设备)
应用正在读建筑的信息
- (void)viewDidLoad{
[super viewDidLoad];
if ([self checkForInternet]) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.distanceFilter = 10.0f;
_locationManager.desiredAccuracy = 20.0f;
[_locationManager startUpdatingLocation];
}
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
if (newLocation.horizontalAccuracy > manager.desiredAccuracy) return;
[self.mapView removeAnnotations:listOfAnn];
[listOfAnn removeAllObjects];
if ([manager locationServicesEnabled]) {
for (NSString* row in rows){
NSArray* cells = [row componentsSeparatedByString:@"\t"];
CLLocationCoordinate2D newCoord;
newCoord.latitude = [[cells objectAtIndex:5]floatValue];
newCoord.longitude = [[cells objectAtIndex:6]floatValue];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
CLLocation *centerLoc = [[CLLocation alloc] initWithLatitude:CAMPUS_LATITUDE longitude:CAMPUS_LONGITUDE];
CLLocationDistance borders = [locB distanceFromLocation:centerLoc];
if ((int)round(borders) > 500) {
BuildingViewController *newBuilding = [[BuildingViewController alloc] initBuildingWithName:[cells objectAtIndex:2] coordinates:newCoord shortDescription:[cells objectAtIndex:4] image:(NSString*)[cells objectAtIndex:3] inDistance: borders];
if ([[prefs stringForKey:newBuilding.title] isEqualToString:[prefs stringForKey:@"userName"]]) {
[newBuilding retrieveID];
[listOfAnn addObject:newBuilding];
}
} else{
CLLocation *locA = [[CLLocation alloc] initWithLatitude:newCoord.latitude longitude:newCoord.longitude];
CLLocationDistance distance = [locA distanceFromLocation:locB];
BuildingViewController *newBuilding = [[BuildingViewController alloc] initBuildingWithName:[cells objectAtIndex:2]
coordinates:newCoord shortDescription:[cells objectAtIndex:4] image:(NSString*)[cells objectAtIndex:3]
inDistance: distance];
if ((int)round(distance) < 100 ||
[[prefs stringForKey:newBuilding.title] isEqualToString:[prefs stringForKey:@"userName"]]){
[newBuilding retrieveID];
[listOfAnn addObject:newBuilding];
}
}
}
[self.mapView addAnnotations:listOfAnn];
}
}
ΓειάσουΛευτέ ρη, 谢谢你对这篇文章的快速回复。我已经阅读过官方文件,但是再次感谢你提及这一点。我正在使用GPS监控,因为正如我所说的,我想为用户提供一个准确的位置。如果重要的位置服务能够满足我的需求,我不能100%确定。你知道重要位置服务的准确度吗? – OutOfBoundsException
Panayioti,正如我所提到的,重要的定位服务和区域监控都非常不准确,并且依靠GSM天线来找到您的位置,而不是GPS。如果您需要准确性,那么请使用GPS方法,但正如我所说的,一旦您获得更新,停止GPS并在给定时间后重新启动它(取决于您的需要,这可能是几秒钟,几分钟等)。 我正在添加一些额外的代码,以便在原始答案中使用gps更新。请看看 – Lefteris
谢谢。你知道为什么蓝点仍在移动,即使我打电话[经理stopUpdatingLocation]; ? – OutOfBoundsException