2012-11-20 44 views
1

我想一些註釋添加到我的MKMapView在這個循環:添加註釋到一個MapView在一個循環

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]; 
} 

這是地址轉換爲使用谷歌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 

事情是我很確定的地址,因爲當我嘗試了他們沒有循環他們的工作。你知道我該如何解決這個問題?

回答

0

您提交了太多查詢,並且您的請求被拒絕。見Geocoding API V2 docs

620: G_GEO_TOO_MANY_QUERIES 

「給出的關鍵字已經超過了請求限制在24小時內或者已經提交在過短的一段時間,太多的要求。如果你正在並行發送或在緊張的多個請求循環,請在代碼中使用計時器或暫停以確保您不會太快地發送請求「

相關問題