Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if current coordinates are within a radius of other coordinates

I have latitude and longitude of a fixed location. I want to check if another location (latitude and longitude) is close enough (50-100 meters) to the fixed location. I use iPhone to get current location.

like image 845
1110 Avatar asked Jan 23 '12 09:01

1110


2 Answers

The method – distanceFromLocation: of CLLocation is exactly what you need.

like image 130
EmptyStack Avatar answered Nov 15 '22 07:11

EmptyStack


distanceFromCurrentLocation = [userLocation distanceFromLocation:destinationlocation]/convertToKiloMeter;
if(distanceFromCurrentLocation < 100 && distanceFromLocation > .500)
{
    NSLog(@"Yeah, this place is inside my circle");
}
else
{
    NSLog(@"Oops!! its too far");
}

This finds the air distance, or we can say, straight line distance only.
Hope you are not looking for road distance.

like image 36
Deepukjayan Avatar answered Nov 15 '22 07:11

Deepukjayan