我正在尝试使用方法将我的lat long转换为地址:
#pragma mark:convert latLong to address
-(void)getMerchantAddress:(NSDictionary *)dict
{
double lata = [[dict valueForKey:@"user_lat"] doubleValue];
double longa = [[dict valueForKey:@"user_long"] doubleValue];
NSLog(@"%f",lata);
NSLog(@"%f",longa);
CLLocation *LocationAtual = [[CLLocation alloc]initWithLatitude:lata longitude:longa];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:LocationAtual completionHandler:^(NSArray *placemarks, NSError *error)
{
if(placemarks && placemarks.count > 0)
{
CLPlacemark *placemark= [placemarks objectAtIndex:0];
NSArray *lines = placemark.addressDictionary[ @"FormattedAddressLines"];
NSString *addressString = [lines componentsJoinedByString:@","];
_usrtAddressLbl.text = addressString;
_userAddressLbl.text = addressString;
}
}];
}
我的应用程序崩溃@ point
[geocoder reverseGeocodeLocation:LocationAtual completionHandler:^(NSArray *placemarks, NSError *error)
显示错误:
[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xb000000000005f53
我该如何解决它。提前谢谢。
答案 0 :(得分:0)
试试这个为我工作
-(void)getMerchantAddress:(NSDictionary *)dict
{
float lata = [[dict objectForKey:@"user_lat"] floatValue];
float longa = [[dict objectForKey:@"user_long"] floatValue];
CLGeocoder *ceo = [[CLGeocoder alloc]init];
CLLocation *loc = [[CLLocation alloc]initWithLatitude:lata longitude:longa]; //insert your coordinates
[ceo reverseGeocodeLocation:loc
completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
if (placemark) {
NSLog(@"placemark %@",placemark);
//String to hold address
strAddress = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
NSLog(@"addressDictionary %@", placemark.addressDictionary);
}else {
}
}
];
}