gpt4 book ai didi

ios - 如何在地理编码中设置标准的 cityOutlet?

转载 作者:行者123 更新时间:2023-11-29 12:48:44 24 4
gpt4 key购买 nike

我正在制作一个应用程序,用户可以在其中设置 UITextField 中的地址并获取 map 上的位置。
我希望 cityOutlet 不可见,但固定在城市“阿姆斯特丹”。

有没有办法做到这一点?我找不到解决这个问题的方法,还是我太笨了..

@property (weak, nonatomic) IBOutlet UITextField *addressOutlet;
@property (weak, nonatomic) IBOutlet UITextField *cityOutlet;

@property (strong, nonatomic) CLLocation *selectedLocation;
@property (strong, nonatomic) NSMutableDictionary *placeDictionary;

- (void)viewDidLoad
{
[super viewDidLoad];

self.addressOutlet.delegate = self;
self.cityOutlet.delegate = self;
self.mapView.delegate = self;

self.placeDictionary = [[NSMutableDictionary alloc] init];
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = 40.740848;
zoomLocation.longitude= -73.991134;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1609.344,1609.344);
[self.mapView setRegion:viewRegion animated:YES];

}

- (void)updatePlaceDictionary {

[self.placeDictionary setValue:self.addressOutlet.text forKey:@"Street"];
[self.placeDictionary setValue:self.cityOutlet.text forKey:@"City"];
}

- (void)updateMaps {

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressDictionary:self.placeDictionary completionHandler:^(NSArray *placemarks, NSError *error) {
if([placemarks count]) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
[self.mapView setCenterCoordinate:coordinate animated:YES];
} else {
NSLog(@"error, geen adres gevonden");
}
}];

}

- (void)delayedReverseGeocodeLocation {

[NSObject cancelPreviousPerformRequestsWithTarget:self];

[self reverseGeocodeLocation];
}

- (void)reverseGeocodeLocation {

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:self.selectedLocation completionHandler:^(NSArray *placemarks, NSError *error) {

if(placemarks.count){
NSDictionary *dictionary = [[placemarks objectAtIndex:0] addressDictionary];
[self.addressOutlet setText:[dictionary valueForKey:@"Street"]];
[self.cityOutlet setText:[dictionary valueForKey:@"City"]];
}
}];
}

- (IBAction)submitTapped:(id)sender {
[self updatePlaceDictionary];
[self updateMaps];
}

最佳答案

-viewDidLoad 中隐藏 UILabel 导出并设置其文本试试这个:

self.cityOutlet.text = @"Amsterdam";
self.cityOutlet.hidden = YES;

然后在您的反向地理编码定位方法中注释掉/删除这一行:

//[self.cityOutlet setText:[dictionary valueForKey:@"City"]];

或者,如果您不使用 cityOutlet 标签来保存字符串,请尝试在您的实现文件中使用 NSString 属性而不是 outlet。

@property (nonatomic, strong) NSString* cityName;

关于ios - 如何在地理编码中设置标准的 cityOutlet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22969286/

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