我从以下地址收到一系列地标:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
..
}
使用NSLog
打印到控制台时,地标以下列形式提供数据:
.. HIDDEN .. St., Brighton ,MA 02135,United States @ 1 + 42.HIDDEN,-71.HIDDEN> +/- 100.00m
但是当使用以下代码时,我将 Boston 作为城市
[placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressCityKey]);
布莱顿是波士顿的一部分,但是如何让控制台日志显示比City键更具体的位置..?
答案 0 :(得分: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 @&lt; + 42.XXXXXX,-71.XXXXXXX&gt; +/- 100.00m”