2013-02-19 65 views
1

我從webservice獲取82個地址,並使用前向地理編碼器。現在,如何在mapview上一次顯示所有82個地址。我將代碼放在for循環中,但它拋出錯誤「對此API密鑰進行了太多查詢」。有什麼辦法可以發送所有地址並獲取所有地址的位置? 這是我在for循環代碼...在地圖上一次刪除82個針腳

NSMutableDictionary *dictLoc = [[self.arrObjects objectAtIndex:indexValue]valueForKey:@"object_location"]; 

    NSString *searchString = [NSString stringWithFormat:@"%@,%@,%@,%@",[dictLoc valueForKey:@"object_location_number"],[dictLoc valueForKey:@"object_location_street"],[dictLoc valueForKey:@"object_location_city"],[dictLoc valueForKey:@"object_location_zip"]]; 

    //  if (self.forwardGeocoder == nil) { 
    BSForwardGeocoder *forwardGeocoder = [[[BSForwardGeocoder alloc] initWithDelegate:self] autorelease]; 
    //  } 

    CLLocationCoordinate2D southwest, northeast; 
    southwest.latitude = 34.172684; 
    southwest.longitude = -118.604794; 
    northeast.latitude = 34.236144; 
    northeast.longitude = -118.500938; 
    BSForwardGeocoderCoordinateBounds *bounds = [BSForwardGeocoderCoordinateBounds boundsWithSouthWest:southwest northEast:northeast]; 

    // Forward geocode! 
#if NS_BLOCKS_AVAILABLE 
    [forwardGeocoder forwardGeocodeWithQuery:searchString regionBiasing:nil viewportBiasing:bounds success:^(NSArray *results) { 
     [self forwardGeocodingDidSucceed:forwardGeocoder withResults:results withIndexValue:indexValue]; 
    } failure:^(int status, NSString *errorMessage) { 
     if (status == G_GEO_NETWORK_ERROR) { 
      [self forwardGeocoderConnectionDidFail:forwardGeocoder withErrorMessage:errorMessage]; 
     } 
     else { 
      [self forwardGeocodingDidFail:forwardGeocoder withErrorCode:status andErrorMessage:errorMessage]; 
     } 
    }]; 
#else 
    [self.forwardGeocoder forwardGeocodeWithQuery:searchString regionBiasing:nil viewportBiasing:nil]; 
#endif 

在此先感謝.. :)

+0

你可以顯示你在寫什麼for循環 – BhushanVU 2013-02-19 10:08:13

+0

發佈一些代碼或錯誤日誌:) – Rushabh 2013-02-19 10:09:33

+0

我已經添加了代碼..和錯誤我在描述中提到.. :) – Rythm 2013-02-19 10:14:29

回答

1

我把代碼中的for循環,但其引發錯誤「太多 查詢已爲此API密鑰而製作。「有沒有辦法發送所有地址的 並獲取所有地址的位置?

否。此錯誤表示您正在使用的API限制了可以進行的查詢次數。只有擺脫這種錯誤的方法,並且顯示所有「82」引腳的原因是要聯繫API開發人員,並瞭解如何增加可以在給定的API中查詢的查詢數量大體時間。有機會,這是一個優質的服務,你可能需要支付這樣的事情。

現在,更好的解決方案是永遠不會在地圖上顯示82個引腳,更像5/10的東西更方便用戶使用。而且有可能你的API會允許每分鐘10個查詢或類似的東西。

更酷的解決方案是構建一個查詢隊列,它只允許您的代碼像10個查詢一樣調用,然後將其他隊列排隊。然後在分配的時間之後,它再做10次查詢。

+0

我已經把延遲,並完成它成功。但它需要12-15秒。我想減少它。 – Rythm 2013-02-19 10:46:16

+0

延遲基於您正在使用的API。如果您可以在至少12-15秒內撥打82個電話,那麼這是您能夠做到的最好的。但是如果API允許縮短最短時間,那麼這顯然是你的目標。 – ColdLogic 2013-02-19 15:35:22

0

它似乎並不像您可以根據API做批量轉發地址解析請求:

@interface BSForwardGeocoder : NSObject <NSURLConnectionDataDelegate> 
- (id)initWithDelegate:(id<BSForwardGeocoderDelegate>)aDelegate; 
- (void)forwardGeocodeWithQuery:(NSString *)searchQuery regionBiasing:(NSString *)regionBiasing viewportBiasing:(BSForwardGeocoderCoordinateBounds *)viewportBiasing; 

#if NS_BLOCKS_AVAILABLE 
- (void)forwardGeocodeWithQuery:(NSString *)searchQuery regionBiasing:(NSString *)regionBiasing viewportBiasing:(BSForwardGeocoderCoordinateBounds *)viewportBiasing success:(BSForwardGeocoderSuccess)success failure:(BSForwardGeocoderFailed)failure; 
#endif 

@property (nonatomic, assign) id<BSForwardGeocoderDelegate> delegate; 
@property (nonatomic, assign) BOOL useHTTP; 

@end 

另外,我還沒有碰到過,做批量地址解析請求的API來,但也許你可以試試一個不同的API(Google Geocoding API?)可能會給你一個更高的請求限制。

相關問題