0

我从以下地址收到一系列地标:

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

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

..HIDDEN.. St., Brighton , MA 02135, United States @ <+42.HIDDEN,-71.HIDDEN> +/- 100.00m

但是当使用以下代码时,我将波士顿作为城市

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

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

4

1 回答 1

0

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

[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 @ <+42.XXXXXX,-71.XXXXXXX> +/- 100.00m"

于 2013-01-14T03:32:17.450 回答