Tuesday, July 17, 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!!!

how to convert distance in kilometer from miles in iPhone

distance = [currentLocation1 distanceFromLocation:currentLocation2]/1609.344;

How to convert distance from current position in iPhone


01-(void)convertToDistance
02{
03 
04    CLLocation* currentLocation1 = [[[CLLocation alloc] initWithLatitude:142.56567 longitude:72.6567 autorelease];
05    CLLocation* currentLocation2 = [[[CLLocation alloc] initWithLatitude:145.8797 longitude:71.8778 autorelease];
06            float distance = 0;
07            float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
08            if(systemVersion >= 4.0){
09                distance =  [currentLocation1 distanceFromLocation:currentLocation2]
10            }
11            else if(systemVersion <= 3.0){
12                distance =  [currentLocation1 getDistanceFrom:currentLocation2]
13            }
14            NSString *temp = [NSStringstringWithFormat:@"%0.1fkm", distance];
15    }

Every coders have error. if you have any doubt or found any mistake in my post, use the comment feature below share with me!
Cheers every Coder!!!

No comments:

Post a Comment