【问题标题】:Not getting Address from latitude and longitude没有从经纬度获取地址
【发布时间】:2012-08-25 15:04:43
【问题描述】:

我正在使用以下代码从当前纬度和经度获取地址,但我无法得到正确的响应

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

    current_latitude=newLocation.coordinate.latitude;
    current_longitude=newLocation.coordinate.longitude;

    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];

    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        if(placemarks && placemarks.count > 0)
        {
            CLPlacemark *placemark= [placemarks objectAtIndex:0];

            NSString * address = [NSString stringWithFormat:@"%@ %@,%@ %@", [placemark subThoroughfare],[placemark thoroughfare],[placemark locality], [placemark administrativeArea]];

            UIAlertView *art = [[UIAlertView alloc] initWithTitle:address message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [art show];
            [art release];
            NSLog(@"%@",address);
        }
    }];
}

【问题讨论】:

  • 欢迎来到 SO,当你说你没有得到正确的回应时!我们不知道您会得到什么回应。所以请详细说明!告诉我们你期待什么,你得到了什么!你自己的代码会被破坏吗?
  • 我在 [placemarks objectAtIndex:0]; 中获取数据,但是根据 doc,当我使用 [placemark locality] 获取数据时,我会得到空值。所有数据都来自 [placemarks objectAtIndex:0];这是正确的,但在使用 locality 时不正确。

标签: iphone ios5


【解决方案1】:

CLLocation 目前覆盖率较差;见this document。您可能正在尝试从覆盖不佳的区域对位置进行地理编码。

如果是这种情况,还有其他地理编码器,例如 Google's Geocoder(需要您在地图上显示结果)。

【讨论】:

    猜你喜欢
    • 2013-07-04
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    相关资源
    最近更新 更多