我目前正在开发一个 iOS 移动应用程序,其中一部分需要确定用户当前位置,并且从当前位置,我想找到最近的位置。
有什么办法可以实现这个吗?
我已经完成了一些编码来查找用户的当前位置。 这是我的代码片段,
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"placemarks=%@",[placemarks objectAtIndex:0]);
但我的问题是,我如何到达最近的其他位置?从我已经获取的当前位置。
提前致谢。
最佳答案
试试这个...
MKPointAnnotation *ann=[MKPointAnnotaion alloc] init];
CLLocationCoordinate2D point = [ann coordinate];
myLocation = [[CLLocation alloc] initWithLatitude:point.latitude longitude:point.longitude];
CLLocationDistance nearByLocation=[yourCurrentLocation distanceFromLocation:myLocation];
关于iphone - 获取距我当前位置最近的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17545344/