我遇到了将位置发送给其他用户的问题。我使用Parse.com作为我的后端,我使用此代码来获得一个位置:位置管理器精度不是很准确
-(void)sendLocation{
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[locationManager stopUpdatingLocation]; //kill it NOW or we have duplicates
if(!self.haveLocation) {
self.haveLocation=YES;
NSLog(@"didUpdateToLocation: %@", newLocation);
self.currentLocation = newLocation;
self.currentLocationGeoPoint= [PFGeoPoint geoPointWithLocation:self.currentLocation];
}
如果我从当前位置给自己发送消息,然后打开该邮件进行查看,通过比较当前的位置圈随着销子的下降,我可以看到他们不在同一个地方,相隔很远。
我有BOOL var haveLocation以确保它只刷新一次。我需要更多次刷新吗?任何关于如何使这更准确的指针将非常感激!由于
我尝试下面的苹果例子LocateMe:
我现在有:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
// test that the horizontal accuracy does not indicate an invalid measurement
if (newLocation.horizontalAccuracy < 0) return;
// test the measurement to see if it is more accurate than the previous measurement
if (self.bestEffortAtLocation == nil || self.bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
// store the location as the "best effort"
self.bestEffortAtLocation = newLocation;
if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
[locationManager stopUpdatingLocation];
//this code after getting the location
NSLog(@"didUpdateToLocation: %@", newLocation);
}
}
}
然而,当我点击发送位置它只运行永远不会停止更新。我也设置了locationManager.desiredAccuracy = kCLLocationAccuracyBest;
。
有你试过不杀死更新,只是记录结果,看看它们是否有所不同? Geoloc可能会非常棘手,就像Rob说的那样,经过几次尝试后,它有可能获得准确性。 –
您还可以将精度精度设置为“最佳” –
我使用了这个locationManager.desiredAccuracy = kCLLocationAccuracyBest; – Kex