Wednesday, November 21, 2012

How to search locations near about 10 km from user location


Today I have write about to getting particular area.
First getting the list of location save into array and passed this array to below function
01-(NSArray *)findNearMe:(NSArray *)lounges {
02NSMutableArray *arNearme = [NSMutableArray array];
03 
04CLLocation *currentLocation;
05 
06for(NSDictionary *d in lounges)
07{
08if([[LocationController sharedInstance] locationKnown] == YES)
09{
10currentLocation = [[LocationController sharedInstance] currentLocation];
11}
12else
13{
14currentLocation = [[CLLocation alloc] initWithLatitude:29.33891 longitude:48.077202];
15}
16//        NSLog(@"Current Location : %@",[currentLocation description]);
17 
18CGFloat latitude=[[d valueForKey:@"latitude"] floatValue];
19CGFloat longitude=[[d valueForKey:@"longitude"] floatValue];
20CLLocation *newPinLocation=[[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
21double distanceValue=[currentLocation distanceFromLocation:newPinLocation];
22 
23if(distanceValue/1000.0<=DISTANCE_RADIUS) {
24//            NSLog(@"Distance value : %f",distanceValue);
25[arNearme addObject:d];
26}
27}
28//    NSLog(@"Near Me Lounges : %d\n%@",[arNearme count], [arNearme description]);
29 
30return  arNearme;
31}
Cheers!!

No comments: