【问题标题】:ReverseGeocodeLocation City not accurate enoughReverseGeocodeLocation City 不够准确
【发布时间】:2013-01-14 03:13:40
【问题描述】:

我从以下地址收到一组地标:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    ..
}

当使用NSLog 打印到控制台时,地标以以下形式为我提供数据:

..HIDDEN.. St.,布莱顿,MA 02135,美国@ +/- 100.00m

但是当使用下面的代码时,我得到 波士顿 作为城市

[placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressCityKey]);

布莱顿是波士顿的一部分,但控制台日志如何显示比城市键更具体的位置..?

【问题讨论】:

  • 副手,看起来 locationManager 可能正在使用更接近的 CLLocationAccuracy 值。
  • Placemarks 也有一个 subLocality 属性,在可能的情况下,它包含更具体的信息,例如城市中的邻里/自治市镇/区的名称——这可能是 description 日志记录的内容到控制台使用,这可以解释为什么即使城市是波士顿,你也会看到布莱顿。
  • 所以我认为会是这样,但 subLocality 提供了另一个更具体的位置,而不是布莱顿或波士顿。我还没有找到description 从哪里得到布莱顿

标签: ios objective-c xcode gps location


【解决方案1】:

看起来你可以用地标做的最好的事情是

[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

这篇文章可能有点用iOS: get Accurate Reverse Geocoding using CLLocationManager?

还值得注意的是,使用波士顿代替布莱顿仍然是同一地点的有效地址。

http://support.apple.com/kb/HT1975

这对我有用:

- (void) resetLocationData{
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager startUpdatingLocation];
    NSLog(@"LAT: %f", [locationManager location].coordinate.latitude);
    NSString *latitude = [NSString stringWithFormat:@"%f", [locationManager location].coordinate.latitude];
    NSString *longitude = [NSString stringWithFormat:@"%f", [locationManager location].coordinate.longitude];
    NSString *latlong = [NSString stringWithFormat:@"%@,%@", latitude, longitude];
    NSLog(@"LONG: %f", [locationManager location].coordinate.longitude);
    NSLog(@"Combined Location: %@", latlong);

    [[locationManager location]timestamp];
}


#pragma mark - CLLOCATION STUFF
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    self.currentLocation = newLocation;
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];

    [geocoder reverseGeocodeLocation:self.currentLocation completionHandler:^(NSArray *placemarks, NSError *error)
     {

         NSLog(@"Placemark is %@", placemarks);
         CLPlacemark *place = [placemarks objectAtIndex:0];
        NSLog(@"placemark 0: %@", place);

        // locationLabel.text = placemarks;

     }];
    if(newLocation.horizontalAccuracy <= 100.0f) {
        [locationManager stopUpdatingLocation];
    }
}

日志输出:

2013-01-13 23:23:05.508 CLLocationTest[47617:907] 地标是 ( "XX XXXXXX Rd, XX XXXXXX Rd, Brighton, MA 02135, United States @ +/- 100.00m"

【讨论】:

  • 我想我不明白的是如何通过 nslog 打印地标显示准确的城市。这是从哪里得到这座城市的?
猜你喜欢
  • 2020-09-12
  • 2018-06-23
  • 2014-09-27
  • 2015-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多