2014-10-15 2 views
0

사용자 테이블이 있고 각 사용자마다 고유 한 위치 (PFGeoPoint 객체)가 있습니다. 이제 가장 가까운 위치에서 사용자를 정렬하고 검색하는 일을하고 싶습니다. 문제는 일부 사용자가 위치 정보 (위도, 경도, geopoint)가 없다는 것입니다. 해당 currentLocation 열은 비어 있습니다. 그게 내가 예상 한대로 쿼리가 작동하지 않는 방식입니다.Parse nearGeoPoint를 사용하여 사용자 위치 검색

나는

[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) { 

    NSLog(@"User is currently at %f, %f", geoPoint.latitude, geoPoint.longitude); 
    self.userLocation = geoPoint; 
    [[PFUser currentUser] setObject:geoPoint forKey:@"currentLocation"]; 
    [[PFUser currentUser] saveInBackground]; 

}]; 

을 구문 분석하는 사용자에게 위치를 저장하는 코드 아래에 넣고에서 코드 아래에 넣어 내 쿼리 방법 검색 당신이하지 않는 사용자를 필터링해야 할 것 소리

PFGeoPoint *userGeoPoint = self.userLocation; //pass user location to PFGeoPoint 

[query whereKey:@"currentLocation" nearGeoPoint:userGeoPoint]; //retrieve users from nearest to rarest 
+0

무엇이 문제입니까? 정확하지 않거나 부정확 한 결과를 반환합니까? 귀하의 질문에 효과가없는 것에 대한 정확한 설명을 추가하십시오. –

+0

issu (구문 분석) _users 테이블에 15 명의 사용자가 있습니다. 일부 사용자에게는 지오 포인트가 있지만 일부 사용자에게는 둥지가 있습니다. 그리고 나는 먼저 geopoint 정보를 가지고 가장 가까운 곳에서 가장 가까운 곳으로 정렬하는 사용자를 데려오고 싶습니다. 그러나 쿼리는 지오 포인트 정보가없는 사용자를 가져 오지 않습니다. – mehmeet43

답변

0

지포가있다.

이 시도 : 위도 0.0, 경도 0.0로

PFGeoPoint *userGeoPoint = self.userLocation; //pass user location to PFGeoPoint 

[query whereKeyExists:@"currentLocation"]; //This is the key line you are missing 
[query whereKey:@"currentLocation" nearGeoPoint:userGeoPoint]; 
+0

Hello Ryan, 답장을 보내 주셔서 감사합니다.하지만 사용자에게 currentLocation이 필요하지 않습니다. 먼저 geopoint 정보가있는 사용자를 검색하여 가장 가까운 곳에서 가장 가까운 곳으로 정렬 한 다음 geopoint 정보가없는 다른 사용자를 검색합니다. – mehmeet43

1

내가 수동으로 업데이트 사용자 GeoPoint의 정보를 사용자가 GeoPoint의 정보를 가지고 있지 않거나 위치를 사용하는 응용 프로그램을 할 수없는 경우. 그런 다음 geoopint 정보가 없는지 가장 가까운 곳에서 사용자를 검색 할 수 있습니다. viewDidLoad에서 사용 된 코드는 다음과 같습니다.

CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; 

if(status == kCLAuthorizationStatusAuthorized || 
    status == kCLAuthorizationStatusAuthorizedAlways || 
    status == kCLAuthorizationStatusAuthorizedWhenInUse) { 

[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) { 

    NSLog(@"User is currently at %f, %f", geoPoint.latitude, geoPoint.longitude); 
    self.userLocation = geoPoint; 
    [[PFUser currentUser] setObject:geoPoint forKey:@"currentLocation"]; 
    [[PFUser currentUser] saveInBackground]; 

}]; 
} 

else if (status == kCLAuthorizationStatusNotDetermined || 
     status == kCLAuthorizationStatusRestricted || 
     status == kCLAuthorizationStatusDenied) { 

    PFGeoPoint *geoPoint = [PFGeoPoint geoPointWithLatitude:0.0 longitude:0.0]; 

    [[PFUser currentUser] setObject:geoPoint forKey:@"currentLocation"]; 
    [[PFUser currentUser] saveInBackground]; 
} 
관련 문제