How to get Distance between two mobiles in ios programming?

Leave a Comment
Get Distance between two Location using ios or iphone Programming. For Getting distance between  two location you need two location using core franwork.
Here i am giving you code snippest for it.


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;
 
   
       CLLocationDistance distanceMeters = [newLocation distanceFromLocation:oldLocation];
             
        NSLog(@"%f",distanceMeters);
     
        UIAlertView *AlertLocation = [[UIAlertView alloc]
                                   initWithTitle:[NSString stringWithFormat:@"%.8f", distanceMeters] message:[NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [AlertLocation show];
//        longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
//        latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
    }
}

This will give you distance between  your current device location and old location of ios or iphone device.
But still it will give some variation for longitude and latitude of user location.
                                                                                   By. WWW.techstudy.com

0 comments:

Post a Comment