gpt4 book ai didi

iphone - iOS 正向地理编码 block 未被执行

转载 作者:可可西里 更新时间:2023-11-01 06:12:19 26 4
gpt4 key购买 nike

为什么这段代码没有被执行?我从我的另一个项目中复制并粘贴了它,它工作得很好。我还在我的其他应用程序中尝试了它,使用的是我在此处插入的相同 addressString,它运行良好。

    NSString *addressString = [NSString stringWithFormat:@"%@ and %@, %@, NY", street, rightBound, [boroughs objectForKey:borough]];
NSLog(@"Address string: %@",addressString);

[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(@"Placemark count:%d",[placemarks count]);

for(CLPlacemark *placemark in placemarks)
{
NSLog(@"%@",placemark);
}

if(anError)
{
NSLog(@"Error: %@",[error description]);
}
}];

任何地标和错误消息都不会记录到控制台。

这是我的整个 AppDelegate.m:

@implementation AppDelegate

@synthesize window = _window;

- (void)dealloc
{
[_window release];
[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSError *error = nil;
SBJsonParser *parser = [[SBJsonParser alloc] init];

NSString *JSONString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Streets" ofType:@"json"] encoding:NSUTF8StringEncoding error:&error];

if(error)
{
NSLog(@"%@",[error description]);
NSLog(@"Break");
}

NSDictionary *dict = [parser objectWithString:JSONString error:&error];
if(error)
{
NSLog(@"%@",[error description]);
NSLog(@"Break");
}

NSArray *addresses = [[dict objectForKey:@"results"] retain];

NSDictionary *boroughs = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Bronx",@"Brooklyn",@"New York", @"Queens",@"Staten Island",nil] forKeys:[NSArray arrayWithObjects:@"B",@"K",@"M",@"Q",@"S", nil]];

int i = 1;
for(NSDictionary *file in addresses)
{
NSString *borough = [file objectForKey:@"Borough"];
NSString *ID = [file objectForKey:@"ID"];
NSString *leftBound = [file objectForKey:@"LeftBound"];
NSString *rightBound = [file objectForKey:@"RightBound"];
NSString *sideOfStreet = [file objectForKey:@"SideOfStreet"];
NSString *street = [file objectForKey:@"Street"];

NSString *addressString = [NSString stringWithFormat:@"%@ and %@, %@, NY", street, rightBound, [boroughs objectForKey:borough]];
// NSLog(@"Address string: %@",addressString);

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *anError)
{
NSLog(@"AAAAAAAAAAAAAAAAAAAAAAAA");
NSLog(@"Placemark count:%d",[placemarks count]);

for(CLPlacemark *placemark in placemarks)
{
NSLog(@"Placemark: %@",placemark);
}

if(anError)
{
NSLog(@"Error: %@",[error description]);
}
}];

[geocoder release];
NSLog(@"%d",i++);
}
[parser release];
[addresses release];

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

return YES;
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([keyPath isEqualToString:@"geocoder"])
{
NSLog(@"AAAAAAA");
}
}

@end

最佳答案

你确定你的“地理编码器”实例不为零吗?
如果您向“nil”对象发送消息,则不会发生任何事情...:)

NSLog(@"%@",geocoder);

关于iphone - iOS 正向地理编码 block 未被执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8549499/

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