DataQueryBeginQueryPoi Method |
Namespace: Telogis.GeoBase
public static IAsyncResult BeginQueryPoi( BoundingBox bbox, PoiType[] type, string nameSubstring, AsyncCallback resultsCallback, Object state )
An asynchronous query is performed in a spiral fashion, starting from the center of the given bounding box.
Initially, a search area, with 3km x 3km dimensions, is centered on the bounding box's center. If the bounding box is smaller than the search area, then the search area is clipped down to size. If all sides are clipped, no more queries will be performed.
If not all sides are clipped, the search starts working in a spiral. After each iteration of the algorithm, it will have queried a square area (unless it hits the bounding box), so at the beginning of each iteration the following queries are planned:
Each box (A,B,C and D) is calculated, and fed into GeoBase for querying. These boxes are clipped to the bounding box if necessary. If a box is clipped entirely (to zero width or height) then the query needn't be performed.
Once all boxes are clipping to zero width or height, the query is complete.
The thickness of the spiral boxes is controlled by T.
class Program { //Poi list static List<Poi> async; //thread wait static ManualResetEvent mre; //Create new bounding box, and center on LatLon static BoundingBox box; static int count; static void Main(string[] args) { mre = new ManualResetEvent(false); //Callback AsyncCallback cb = new AsyncCallback(ar); //Dimensions box = new BoundingBox(); box.Add(new LatLon(34, -118)); box.Inflate(0.25); Console.WriteLine(DateTime.Now); count = 0; //Create list async = new List<Poi>(); //start query - using boundary box and callback DataQuery.BeginQueryPoi(box, null, null, cb, null); //thread wait (until signaled) mre.WaitOne(); Console.WriteLine(count); //Stop console closing automatically Console.ReadKey(); } //Callback method static void ar(IAsyncResult cb) { bool comp; Poi[] res = DataQuery.EndQueryPoi(cb, out comp); if (res.Length > 0) { //update list count += res.Length; async.AddRange(res); Console.WriteLine("{0}:{1} - {2} - {3:0.0}", DateTime.Now, res.Length, res[0].Name, res[0].Location.DistanceTo(box.Center, DistanceUnit.KILOMETERS)); } else { Console.WriteLine("{0}:{1}", DateTime.Now, res.Length); } if (cb.IsCompleted) { //set to signaled state mre.Set(); } } }