1

我正在尝试在此循环中向我的 mkMapView 添加一些注释:

for (PFObject *fetchedCompany in companyArray)
{
       Store *store = [[Store alloc] initWithObject:fetchedCompany];
       [self loadStore:store];
       [store release];
}

- (void) loadStore:(Store *) store {
    CLLocationCoordinate2D location = [self getLocationFromAddressString:store.address];
    MapViewAnnotation *mapAnnotation = [[MapViewAnnotation alloc] initWithTitle:store.name coordinate:location];
    [self.indexMapView addAnnotation:mapAnnotation];
}

这是使用 google api 将地址转换为位置的 getLocationFromAddressString 方法:

-(CLLocationCoordinate2D) getLocationFromAddressString:(NSString*) addressStr {
    NSString *urlStr = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", [addressStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSError *error = nil;

    NSString *locationStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlStr] encoding:NSUTF8StringEncoding error:&error];

    NSArray *items = [locationStr componentsSeparatedByString:@","];

    double lat = 0.0;
    double lon = 0.0;

    if([items count] >= 4 && [[items objectAtIndex:0] isEqualToString:@"200"]) {
        lat = [[items objectAtIndex:2] doubleValue];
        lon = [[items objectAtIndex:3] doubleValue];
    }
    else {
        NSLog(@"Address, %@ not found: Error %@",addressStr, [items objectAtIndex:0]);
    }

    CLLocationCoordinate2D location;
    location.latitude = lat;
    location.longitude = lon;

    return location;
}

当我只发送一个位置时,它总是可以完美运行,但是当我在循环中添加注释时,有时无法识别某些位置,并且我从我的 NSLog 中得到了错误:

Address, Vallgatan 3 GÖTEBORG not found: Error 620

问题是我对地址很确定,因为当我在没有循环的情况下尝试它们时它们起作用了。你知道我该如何解决这个问题吗?

4

1 回答 1

0

您提交的查询过多,您的请求被拒绝。请参阅地理编码 API V2 文档

620:    G_GEO_TOO_MANY_QUERIES

"The given key has gone over the requests limit in the 24 hour period or has submitted too many requests in too short a period of time. If you're sending multiple requests in parallel or in a tight loop, use a timer or pause in your code to make sure you don't send the requests too quickly"

于 2012-11-20T20:40:57.833 回答