iOS开发中地图(MapKit)的使用

#import <MapKit/MKMapView.h>

<MKMapViewDelegate,CLLocationManagerDelegate>

{

    CLLocationDegrees lati;

    CLLocationDegrees longti;

    NSMutableArray *chooseArray;

    NSMutableArray *tittleArray;

    

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    //初始化地图视图

    MKMapView* mapview = [[MKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

    //地图的代理方法

    mapview.delegate = self;

    //是否显示当前的位置

    mapview.showsUserLocation = YES;

    //地图的类型, iOS开发中自带的地图

    //使用第三方的地图可以查找周边环境的餐馆,学校之类的

    /*

     MKMapTypeStandard 标准地图

     MKMapTypeSatellite 卫星地图

     MKMapTypeHybrid 混合地图

     */

    mapview.mapType = MKMapTypeStandard;

    

    //河南南阳的经纬度,初始化的坐标

    CLLocationCoordinate2D coor2d = {33.00,112.52};

    //CLLocationCoordinate2D coor2d = {37.7,112.4};

    //显示范围,数值越大,范围就越大

    MKCoordinateSpan span = {5,5};

    MKCoordinateRegion region = {coor2d,span};

    //是否允许缩放,一般都会让缩放的

    //mapview.zoomEnabled = NO;

    //mapview.scrollEnabled = NO;

    //地图初始化时显示的区域

    [mapview setRegion:region];

    [self.view addSubview:mapview];

    locationmanager = [[CLLocationManager alloc]init];

    

    //设置精度

    /*

     kCLLocationAccuracyBest

     kCLLocationAccuracyNearestTenMeters

     kCLLocationAccuracyHundredMeters

     kCLLocationAccuracyHundredMeters

     kCLLocationAccuracyKilometer

     kCLLocationAccuracyThreeKilometers

     */

    //设置定位的精度

    [locationmanager setDesiredAccuracy:kCLLocationAccuracyBest];

    //实现协议

    locationmanager.delegate = self;

    NSLog(@"开始定位");

    //开始定位

    [locationmanager startUpdatingLocation];

    

}


#pragma mark locationManager delegate


//实现定位 6.0 过期的做法

- (void)locationManager:(CLLocationManager *)manager

    didUpdateToLocation:(CLLocation *)newLocation

           fromLocation:(CLLocation *)oldLocation

{

    NSLog(@"hello");

    //打印出精度和纬度

    CLLocationCoordinate2D coordinate = newLocation.coordinate;

    NSLog(@"输出当前的精度和纬度");

    NSLog(@"精度:%f 纬度:%f",coordinate.latitude,coordinate.longitude);

    //停止定位

    [locationmanager stopUpdatingLocation];

    //计算两个位置的距离

    float distance = [newLocation distanceFromLocation:oldLocation];

    NSLog(@" 距离 %f",distance);

    

    //====位置的反编码 5.0 之后的

    /*

     

     */

    

    geocoder = [[CLGeocoder alloc]init];

    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray*placemarks,NSError* error)

     {

         //NSLog(@"hffjv");

         for (CLPlacemark* place in placemarks) {

             //NSLog(@"hffjv");

             NSLog(@"name %@",place.name); //位置

             NSLog(@"thoroughfare %@",place.thoroughfare);//街道

             //子街道

             NSLog(@"subthoroughfare %@",place.subAdministrativeArea);

             //

             NSLog(@"loclitity %@",place.locality);

             //

             NSLog(@"subLocality %@",place.subLocality);

             //国家

             NSLog(@"country %@",place.country);

             NSLog(@"hffjv");

         }

         

     }];

}


// 6.0 之后新增的位置调用方法


/*-(void)locationManager:(CLLocationManager *)manager

 didUpdateLocations:(NSArray *)locations

 {

 for (CLLocation* location in locations) {

 NSLog(@"%@",location);

 }

 //停止定位

 // [manager stopUpdatingLocation];

 

 }

 */

#pragma mark MKMapViewDelegate的代理方法

//返回标注视图(大头针视图)

/*- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <mkannotation>)annotation

 {

 

 }*/


//更新当前位置调用

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

{

    

}

//选中注释图标

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

{

    

}

//地图的显示区域改变了调用

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

{

    

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值