CLGeocoder返回不准确的结果

时间:2014-12-12 04:07:57

标签: ios objective-c clgeocoder

我在CLGeocoder中使用方法geocodeAddressString:(NSString *)addressString inRegion:(CLRegion *)region completionHandler:(CLGeocodeCompletionHandler)completionHandler,它返回地址字符串Beverly Hills,CA的错误坐标。它仅在设备上执行此操作。它在模拟器上运行良好。坏坐标仍然处于CA的状态,但它们并非靠近Beverly Hills实际所在的位置。有任何想法吗?这是我的默认搜索区域:

#define kDefaultSearchRegion [[CLCircularRegion alloc] initWithCenter:CLLocationCoordinate2DMake(40.0, -100.0) radius:2758000.0 identifier:@"USA"]

这是我的代码:

- (void)onLocationSelected:(NSString *)location{
CLGeocoder *geocoderRequest;
__weak MTSRViewController *weakSelf = self;

  geocoderRequest = [[CLGeocoder alloc] init];

  //Show the loading view
    self.hud.taskInProgress = YES;
    [self.hud show:YES];

  [geocoderRequest geocodeAddressString:location
                               inRegion:kDefaultSearchRegion
                      completionHandler:^(NSArray *placemarks, NSError *error) {
                          if (error) {
                              DLog(@"Geocoder fail %@",error);
                              [MTUtils alert:@"Unable to reach the internet. Please check your connection."];
                              weakSelf.hud.taskInProgress = NO;
                              [weakSelf.hud hide:YES];
                              return;
                          }

                          CLLocation *geocodedLocation;
                          NSString *formattedLocation;

                          geocodedLocation = [(CLPlacemark *)[placemarks lastObject] location];

                          formattedLocation = [weakSelf formattedStringFromCoordinate:[geocodedLocation coordinate]];

                          //Store for later
                          [weakSelf setPlacemark:[placemarks lastObject]];

                          [weakSelf updateSearchTags:@{
                                                       @"location": location,
                                                       @"where":formattedLocation
                                                       }];

                          [weakSelf reloadSearchResults];

                      }];

  //If there is an existing geocoder request, cancel it
  if ([[self geocoder] isGeocoding]) {
    [[self geocoder] cancelGeocode];
  }

  //Retain a reference so we can cancel the request
  [self setGeocoder:geocoderRequest];
}

我得到的是北加州的某个地区,这个地方离我很近。

0 个答案:

没有答案