gpt4 book ai didi

ios - 我可以将返回的 CLLocationDistance 添加到 NSMutableArray 中吗?

转载 作者:行者123 更新时间:2023-11-29 13:54:19 29 4
gpt4 key购买 nike

我正在使用以下代码主体查找已登录用户与我的应用程序数据库中其他用户列表之间的距离。

ViewController.h

@property (nonatomic) CLLocationDistance kilometers;

ViewController.m

NSString *myLocation = self.currentUser[0][@"street_address"];
NSLog(@"MY LOCATION %@", myLocation);


CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:myLocation completionHandler:^(NSArray* placemarks2, NSError* error){
for (CLPlacemark* aPlacemark in placemarks2)
{

for (NSMutableDictionary *multiplelocationsFriend in self.closeByNeighbours) {

NSString *location = [multiplelocationsFriend objectForKey:@"address"];

CLGeocoder *geocoderFriend = [[CLGeocoder alloc] init];
[geocoderFriend geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];


self.endLocation = [[CLLocation alloc] initWithLatitude:placemark.location.coordinate.latitude longitude:placemark.location.coordinate.longitude] ;


NSString *myLocation = self.currentUser[0][@"street_address"];
NSLog(@"MY LOCATION %@", myLocation);

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:myLocation completionHandler:^(NSArray* placemarks2, NSError* error){
for (CLPlacemark* aPlacemark in placemarks2)
{
self.startLocation = [[CLLocation alloc] initWithLatitude:aPlacemark.location.coordinate.latitude longitude:aPlacemark.location.coordinate.longitude] ;

self.kilometers = [self.startLocation distanceFromLocation:self.endLocation] / 1000;


}
}];


}
}
];
}

}
}];




dispatch_async(dispatch_get_main_queue(), ^{
[self.neighboursView reloadData];
});



} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", [error localizedDescription]);
}];

有什么方法可以将 self.kilometers 添加到 NSMutableArray 中吗?当我尝试这样做时,XCode 向我抛出一条错误消息:

Sending 'CLLocationDistance' (aka 'double') to parameter of incompatible type 'id _Nonnull'

最佳答案

您必须将其转换为 NSNumber

NSMutableArray *a = [NSMutableArray new];
[a addObject:[NSNumber numberWithDouble:self.kilometers]];

关于ios - 我可以将返回的 CLLocationDistance 添加到 NSMutableArray 中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57698407/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com