我正在研究側重於建築物(校園)中的行人的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