进阶 13-5 通过地理编码调用系统地图地位



#import "GeocoderTwoViewController.h"
#import 
#import 
@interface GeocoderTwoViewController ()
/*  地标 */
@property (strong,nonatomic) CLGeocoder *geocoder;
@end

@implementation GeocoderTwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.geocoder = [[CLGeocoder alloc] init];
    [self location_1];
    [self Location_2];
}


#pragma mark --- 确定一个城市的位置 ---
- (void)location_1{
    [self.geocoder geocodeAddressString:@"北京市" completionHandler:^(NSArray * placemarks, NSError * error) {
        //获取第一个地标
        CLPlacemark *CLPlaceMark = [placemarks firstObject];
        
        //将定位地标转换为地图地标
        MKPlacemark *MKplaceMark = [[MKPlacemark alloc] initWithPlacemark:CLPlaceMark];
        
        //字典中放一个地图类型
        NSDictionary *Options = @{MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard)};
        //初始化地图组
        MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:MKplaceMark];
        //打开地图,根据地图类型
        [mapItem openInMapsWithLaunchOptions:Options];
        
    }];
}

- (void)Location_2{
    [self.geocoder geocodeAddressString:@"北京市" completionHandler:^(NSArray * _Nullable placemarks, NSError * _Nullable error) {
        //获取第一个地标
        CLPlacemark *CLPlaceMarkBJ = [placemarks firstObject];
        //将定位地标转换为地图地标
        MKPlacemark *MKPlaceMarkBJ = [[MKPlacemark alloc] initWithPlacemark:CLPlaceMarkBJ];
        
        [self.geocoder geocodeAddressString:@"九龙" completionHandler:^(NSArray * _Nullable placemarks, NSError * _Nullable error) {
            //获取第一个地标
            CLPlacemark *CLPlaceMarkWA = [placemarks firstObject];
            //将定位地标转换为地图地标
            MKPlacemark *MKPlaceMarkWA = [[MKPlacemark alloc] initWithPlacemark:CLPlaceMarkWA];
            //字典中放一个地图类型
            NSDictionary *Options = @{MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard)};
            MKMapItem *item1 = [[MKMapItem alloc] initWithPlacemark:MKPlaceMarkBJ];
            MKMapItem *item2 = [[MKMapItem alloc] initWithPlacemark:MKPlaceMarkWA];
            [MKMapItem openMapsWithItems:@[item1,item2] launchOptions:Options];
        }];
    }];
}
@end

你可能感兴趣的:(进阶 13-5 通过地理编码调用系统地图地位)