获取位置信息使用CLPlaceMark和CLGeocoder

时间:2013-04-16 07:05:13

标签: iphone mkmapview mapkit mkannotation ios6-maps

我已经完成了在ios 6中的地图上使用ClLocationCoordinate2D动态绘制两个地方之间的路线。任何人都可以帮助我使用CLPlacemark和CLGeocoder获取位置名称,因为反向地理编码器已在ios 6中弃用。

2 个答案:

答案 0 :(得分:1)

你可以通过其委托方法获得bellow等信息。

<强>更新

首先在.h文件中定义此变量,如bellow ..

NSString *postcode,*locationName;

并以波纹管方式使用它......

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        for (CLPlacemark * placemark in placemarks) {
            postcode = [placemark postalCode];
            [postcode retain];
            locationName = [placemark name];
            [locationName retain];

            NSLog(@"\n placemark %@",placemarks);
        }    
    }];
    [geoCoder release];
    NSLog(@"\n Location Name ==> %@  ----> GotPostCode:%@",locationName,postcode);
}

此处您还可以使用CLGeocoder的其他属性,例如localitylocation等...

答案 1 :(得分:0)

CLPlacemark对象存储给定纬度和经度的地标数据。地标数据包括与指定坐标关联的国家,州,城市和街道地址等信息。

Check Link