iOS开发中最基本的位置功能实现示例

2020-01-14 16:25:30王冬梅

        NSLog(@"街道 = %@n 省 = %@n 城市 = %@",address,state,city);  
    }  
}]; 

 

地图的使用以及标注地图
使用CoreLocation框架获取了当前设备的位置,这一章介绍地图的使用。
首先,导入<MapKit.framework>框架:

复制代码
#import <MapKit/MapKit.h>
main代码示例

 

 

复制代码
main.h  
  
#import <UIKit/UIKit.h>  
#import <MapKit/MapKit.h>  
//  引用地图协议  
@interface HMTMainViewController : UIViewController<MKMapViewDelegate>  
  
@end  
  
main.m  
  
//  
//  HMTMainViewController.m  
//  Map  
//  
//  Created by HMT on 14-6-21.  
//  Copyright (c) 2014年 humingtao. All rights reserved.  
//  
  
#import "HMTMainViewController.h"  
#import "HMTAnnotation.h"  
  
@interface HMTMainViewController ()  
  
@property (nonatomic ,strong) MKMapView *mapView;  
  
@end  
  
@implementation HMTMainViewController  
  
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
{  
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
    if (self) {  
        // Custom initialization  
    }  
    return self;  
}  
  
- (void)viewDidLoad  
  
{  
      
    [super viewDidLoad];  
    self.view.backgroundColor = [UIColor redColor];  
      
    // Do any additional setup after loading the view.  
      
    self.navigationItem.title = @"地图标注";  
    self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];