我遇到了將位置發送給其他用戶的問題。我使用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