2012-01-23 20 views

答えて

1
CLLocation *location;// = init...; 
double distance = [location distanceFromLocation:otherLoc]; //in meters 
1

私は空のスタック答え.. をUpvotedが、あなたはより多くの助けが必要な場合は、ここでコードが..です

は、あなたの実装クラスで、その後CLLocationManagerDelegateうと。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ 


      int distance = [newLocation distanceFromLocation:oldLocation]; 
      if(distance >50 && distance <100) 
      { 

      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Distance" 
                  message:[NSString stringWithFormat:@"%i meters",distance] 
                  delegate:nil 
                cancelButtonTitle:@"OK" 
                otherButtonTitles:nil]; 
      [alert show]; 
      [alert release]; 
      } 
     } 
    } 
7
distanceFromCurrentLocation = [userLocation distanceFromLocation:destinationlocation]/convertToKiloMeter; 
if(distanceFromCurrentLocation < 100 && distanceFromLocation > .500) 
{ 
    NSLog(@"Yeah, this place is inside my circle"); 
} 
else 
{ 
    NSLog(@"Oops!! its too far"); 
} 

これは空気間隔を見つけ、あるいは我々は、唯一の直線距離を言うことができます。
あなたは道路の距離を探していないことを願っています。

1

彼の答えを使用する前に、参照を定義するためにCLLocationを使用し、Deepukjayan答えに追加:

CLLocation *montreal = [[CLLocation alloc] initWithLatitude:45.521731 longitude:-73.628679]; 
0
func distance(from location: CLLocation) -> CLLocationDistance 

Documentation

関連する問題