2014-10-19 2 views
0

다음 코드를 사용하여 가까운 클리닉의 위치를 ​​kms로 얻으므로 코드가 잘 작동합니다. 하지만 내가 이해할 수없는 것은 파스 개체를 100 개 개체 만 반환하는 방법입니다. 그래서 내 질문은 내가 현재 클리닉의 길고 위도와 일치하는 하위 집합을 반환하는 방법이어야한다고 생각합니다.Parse API - 검색 결과의 범위를 좁히려면 어떻게해야합니까?

나는이 문법적으로 정확하지 않을 수 있습니다

List<Clinics> _clicics; 
_clicics =GetAllNearestFamousPlaces (54.269412, -0.93399086); 


public List<Clinics> GetAllNearestFamousPlaces(double currentLatitude,double currentLongitude) 
    { 
     List<Clinics> Caldistance = new List<Clinics>(); 

     var query = ParseObject.GetQuery("clinics"); 
     query.FindAsync().ContinueWith(t => 
      { 

     IEnumerable<ParseObject> results = t.Result; 
     foreach (var obj in results) 
     { 
      double distance = Distance(currentLatitude, currentLongitude, obj.Get<double>("lat"), obj.Get<double>("long")); 
      if (distance < 25)   //nearbyplaces which are within 25 kms 
      { 
       Clinics dist = new Clinics(); 
       dist.Name = obj.Get<string>("Name"); 
       dist.Latitute = obj.Get<double>("lat"); 
       dist.Longitude =obj.Get<double>("long"); 
       Caldistance.Add(dist); 
        } 
       } 
      }); 

     return Caldistance; 


    } 


    private double Distance(double lat1, double lon1, double lat2, double lon2) 
    { 
     double theta = lon1 - lon2; 
     double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta)); 
     dist = Math.Acos(dist); 
     dist = rad2deg(dist); 
     dist = (dist * 60 * 1.1515)/0.6213711922;   //miles to kms 
     return (dist); 
    } 


    private double deg2rad(double deg) 
    { 
     return (deg * Math.PI/180.0); 
    } 

    private double rad2deg(double rad) 
    { 
     return (rad * 180.0/Math.PI); 
    } 
+0

를 기반으로 추측하고있어 구문 분석을 사용하지 않는, 귀하의 질문에 의미있는 제목을주십시오. 필자는 이전에 Parse 문서에서 Limit 및 Skip을 사용하여 기본 100 제한을 피하는 방법을 설명했습니다. 읽었습니까? 이러한 동일한 문서는 쿼리에 제약 조건을 추가하여 결과 집합의 크기를 제한하는 방법에 대한 예제를 제공합니다. – Jason

+0

나는 그것을 보았다. 그러나 그것은 얼마나 많은 페이지가 생략해야하는지 caculualte하는 법을 당신에게 말해주지 않는다! !!! – rogue39nin

+0

u는 제한을 말하고 건너 뛰고 플링 할 수 있습니다 – rogue39nin

답변

0

내 viewdIdLoadMethod에 아래의 함수를 호출 - 실제로 다시 그래서 그들의 문서

// assume your point of origin is 54.269412, -0.93399086 
// each degree of lat/long is **roughly** 100 km so we'll fudge and +- .5 to narrow down the 
// list of clinics 

double lat = 54.269412; 
double lng = -0.93399086; 

double minLong = lng - 0.5; 
double maxLong = lng + 0.5; 
double minLat = lat - 0.5; 
double maxLat = lat + 0.5; 

var query = from clinic in ParseObject.GetQuery("clinics") 
      where clinic.Get<double>("lat") >= minLat 
      and clinic.Get<double>("lat") <= maxLat 
      and clinic.Get<double>("long") >= minLat 
      and clinic.Get<double>("long") <= maxLat 
      select clinic; 

// 1000 is the max we can request at a time 
query = query.Limit(1000); 

// now execute your query to get the results, and then use your Distance() function to calculate 
// the precise distance and remove results that are to far away, etc 
관련 문제