您的位置:首页 > 其它

关于coreLocation - 地理位置反向编码

2012-06-08 09:50 274 查看
转自:http://blog.csdn.net/csj1987/article/details/6658895

CoreLocation中得到的定位信息都是以经度和纬度等表示的地理信息,很多时候我们需要把它反向编码成普通人能读懂的地理位置描述如:X国XX市XXX区XXX街道XX号,这就需要用到MapKit中的一个地理位置反向编码工具:MKReverseGeocoder,

用法:

1,首先要实现协议MKReverseGeocoderDelegate,因为将坐标信息发到服务器再反回来需要一定的时间,所以为了防止阻塞,发出信息后并不知到什么时候会返回信息,信息返回时会通知委托方法。这里实现这个类主要时为了实现2个方法如下:

[plain] view
plaincopy

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{

NSLog(@"MKReverseGeocoder has failed.");

}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{

NSLog(@"当前地理信息为:%@",placemark);

}

didFailWithError这个方法是来处理返回错误信息的,didFindPlacemark则是地理信息返回了,地理信息包含在placemark里面,此对象中包含国家,城市,区块,街道等成员变量。

2,然后可以init一个反向编码器,然后发出请求了:

[plain] view
plaincopy

MKReverseGeocoder *reverseGeocoder =[[MKReverseGeocoder alloc] initWithCoordinate:coordinate];

NSLog(@"%g",coordinate.latitude);

NSLog(@"%g",coordinate.longitude);

reverseGeocoder.delegate = self;

[reverseGeocoder start];

MKReverseGeocoder除了start方法,还有cancel方法来取消请求。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: