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);
}