ios6下使用CLGeocoder替换MKReverseGeocoder

ios5后,使用apple自己的地图了,在地理编码上也由CLGeocoder替换MKReverseGeocoder。 具体如下:

包含: #import <CoreLocation/CoreLocation.h>

ios5之前

   @interface MainViewController : UIViewController <CLLocationManagerDelegate,MKMapViewDelegate,MKReverseGeocoderDelegate> {

ios5之之后

   @interface MainViewController : UIViewController <CLLocationManagerDelegate,MKMapViewDelegate,MKReverseGeocoderDelegate> {

删除MKReverseGeocoderDelegate协议。


.m文件

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


//ios <5

 /MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
    geocoder.delegate = self;
    [geocoder start];

//ios >=5

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation: newLocation completionHandler:^(NSArray *array, NSError *error) {
    if (array.count > 0) {
        
        CLPlacemark *placemark = [array objectAtIndex:0];
        NSString *country = placemark.ISOcountryCode;
        NSString *city = placemark.locality;
        
        NSLog(@"---%@..........%@..cout:%d",country,city,[array count]);
    }
    }];

//ios< 5

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
    
   /* MapLocation *annotation = [[MapLocation alloc] init];
    annotation.streetAddress = placemark.thoroughfare;
    annotation.city = placemark.locality;
    annotation.state = placemark.administrativeArea;
    annotation.zip = placemark.postalCode;
    annotation.coordinate = geocoder.coordinate;
    [mapView addAnnotation:annotation];
    
    [annotation release];
    geocoder.delegate = nil;
    [geocoder autorelease];*/
    
    NSLog(@"--%@.%@.%@.%@.%f.%f....",placemark.thoroughfare,placemark.locality,placemark.administrativeArea,placemark.postalCode,placemark.coordinate.latitude,placemark.coordinate.longitude);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值