您实际上不应该尝试控制哪些硬件正在为您获取位置。如果您想要更高的准确度,您可以检查由 提供给您的准确度,CLLocation
如果它不是您想要的,则将其丢弃。
或者,您可以读取一堆读数并使用我编写的这段代码对它们进行平均!您将一组CLLocation
对象传递给它,它会返回一个平均位置。我在我的一个应用程序中使用它,它提供了很高的准确性(如果您使用 >5 个位置,通常在一米内)。
- (CLLocation *) averageLocations: (NSArray *) loci
{
double tempLat=0,tempLong=0,tempAlt=0,tempAccH=0,tempAccV=0,tempCourse=0,tempSpeed=0,tempTime=0;
for (CLLocation *loc in loci)
{
tempLat += loc.coordinate.latitude;
tempLong += loc.coordinate.longitude;
tempAlt += loc.altitude;
tempAccH += loc.horizontalAccuracy;
tempAccV += loc.verticalAccuracy;
tempCourse += loc.course;
tempSpeed += loc.speed;
tempTime += loc.timestamp.timeIntervalSinceReferenceDate;
}
double ratio = (double) loci.count;
CLLocationCoordinate2D tempCoord = CLLocationCoordinate2DMake(tempLat/ratio, tempLong/ratio);
NSDate *tempDate = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate:tempTime/ratio];
CLLocation *temp = [[CLLocation alloc] initWithCoordinate:tempCoord
altitude:tempAlt/ratio
horizontalAccuracy:tempAccH/ratio
verticalAccuracy:tempAccV/ratio
course:tempCourse/ratio
speed:tempSpeed/ratio
timestamp:tempDate];
return temp;
}