在地图上一次放下82个针脚

时间:2013-02-19 10:05:23

标签: iphone ios objective-c

我从网络服务获得了82个地址,我正在使用前向地理编码器。现在如何在mapview上一次显示所有82个地址。我将代码放入for循环但是它抛出错误“已经为此API密钥进行了太多查询”。有没有办法发送所有地址并获取所有地址的位置? 这是我在for循环中的代码......

 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

先谢谢.. :))

2 个答案:

答案 0 :(得分:1)

  

我把代码放在for循环中,但它抛出错误“太多了   已经为此API密钥进行了查询。“有没有办法发送所有密钥   地址和获取所有地址的位置??

没有。此错误表示您使用的API限制了您可以进行的查询数量。只有这样才能摆脱这个错误,并根据你想要的原因显示所有“82”引脚,是联系API开发人员并找出如何在给定的API中增加查询的数量大体时间。有可能它是一项优质服务,您可能需要为此付出代价。

现在,一个更好的解决方案是永远不会在地图上显示82个引脚,更像是5/10更加用户友好。很有可能你的API将允许每分钟10个查询或类似的东西。

更酷的解决方案是构建一个查询队列,只允许您的代码像10个查询一样调用,然后将其他查询排队。然后在规定的时间之后再进行10次查询。

答案 1 :(得分: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?),这可能会为您提供更高的请求限制。