OC开发_Storyboard——MapKit

时间:2023-03-10 02:32:35
OC开发_Storyboard——MapKit

一、Core  Location

1、基本对象

@propertys: coordinate, altitude, horizontal/verticalAccuracy, timestamp, speed, course

@property (readonly) CLLocationCoordinate2D coordinate;

typedef {

CLLocationDegrees latitude; //   double型 纬度

CLLocationDegrees longitude; //  double 型 经度

} CLLocationCoordinate2D;

@property (readonly) CLLocationDistance altitude;  //高度 (单位:米)

2、精度

kCLLocationAccuracyBestForNavigation  //精度最好,但同时最耗电,以下类推

kCLLocationAccuracyBest

kCLLocationAccuracyNearestTenMeters

kCLLocationAccuracyHundredMeters

kCLLocationAccuracyKilometer

kCLLocationAccuracyThreeKilometers

3、如何获得Core Location?[通过CLLocationManager]

通常的步骤是:(1 通过硬件获得支持  (2 创建一个CLLocationManager实例并设置委托 (3 配置如何更新、精度 (4 开启这个Manager运行

4、在最开始创建Location Manager的时候,需要检查下面这些项:

+ (CLAuthorizationStatus)authorizationStatus; //* 检查应用的授权状态 *应用在第一次启动时,会自动请求授权,应用应当明确被授权使用位置服务,并且位置服务当前出于运行状态,应用才能使用位置服务。

+ (BOOL)locationServicesEnabled; // * 判断用户是否启动位置服务 * 在启动位置更新操作之前,用户应当检查该方法的返回值来查看设备的位置服务是否启动。如果位置服务没有启动,而用户又启动了位置更新操作,那么Core Location 框架将会弹出一个让用户确认是否启动位置服务的对话框。

+ (BOOL)significantLocationChangeMonitoringAvailable; //* 表明设备能否报告基于significant location changges的更新 *(significant location change监控,只是基于设备所链接的蜂窝塔的位置改变诊断,在精度要求不高的情况下,可以节省很多电量。)

+(BOOL)isMonitoringAvailableForClass:(Class)regionClass;//  对某些设备 beacon的监听

+ (BOOL)isRangingAvailable;//* 返回蓝牙信号范围服务是否可用 *。这是iOS 7新增的方法

5、委托

(1 属性

@property CLLocationAccuracy desiredAccuracy; // 精度

@property CLLocationDistance distanceFilter; // 距离过滤器:超过多远的距离才开始重新定位

(2 定位

- (void)startUpdatingLocation;   //开启定位
 - (void)stopUpdatingLocation;   //关闭定位

- (void)startMonitoringSignificantLocationChanges;    //可以在后台或者前台都能监视到用户位置的移动,即使程序没有启动

- (void)stopMonitoringSignificantLocationChanges;  //

(3 当你的程序没有运行或者后台被启动的时候,这个方法会被发送

application:didFinishLaunchingWithOptions:  UIApplicationLaunchOptionsLocationKey

(4 圆形范围[基于对区域的监控]

- (void)startMonitoringForRegion:(CLRegion *)region; // CLCircularRegion/CLBeaconRegion

- (void)stopMonitoringForRegion:(CLRegion *)region;

//进入范围的时候,会发送广播通知你[这是iOS7 新增的]

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region

withError:(NSError *)error;

接下就可以讲讲MapKit:

二、MKMapView

1、annotations :通过点击会弹出一个 MKAnnotationView

@property (readonly) NSArray *annotations;

@protocol  MKAnnotation <NSObject>

@property  (readonly) CLLocationCoordinate2D coordinate;//

@optional

@property  (readonly) NSString *title;  //标题

@property  (readonly) NSString *subtitle;//副标题

@end

typedef {

CLLocationDegrees latitude;

CLLocationDegrees longitude;//经纬度

} CLLocationCoordinate2D;

OC开发_Storyboard——MapKit

2、MKAnnotationView

@property id <MKAnnotation> annotation;

@property UIImage *image;  //可以修改如上图的大头针的图片
@property UIView *leftCalloutAccessoryView;  //弹出View的修改
@property UIView *rightCalloutAccessoryView;

@property BOOL enabled;

@property CGPoint centerOffset;

@property BOOL draggable;

(1 [非常像UITableView]创建视图(不创建会自动创建)

- (MKAnnotationView *)mapView:(MKMapView *)sender viewForAnnotation:(id <MKAnnotation>)annotation

{

MKAnnotationView *aView = [sender dequeueReusableAnnotationViewWithIdentifier:IDENT];

if (!aView) {

aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation

reuseIdentifier:IDENT];

aView.annotation = annotation;

return aView;

}

(2  View里面的图标被轻点事件

- (void)mapView:(MKMapView *)sender   annotationView:(MKAnnotationView *)aView

calloutAccessoryControlTapped:(UIControl *)control;

(3 大头针被轻点事件

- (void)mapView:(MKMapView *)sender didSelectAnnotationView:(MKAnnotationView *)aView

{

if ([aView.leftCalloutAccessoryView isKindOfClass:[UIImageView class]])

{

UIImageView *imageView = (UIImageView *)aView.leftCalloutAccessoryView;

imageView.image = ...;

}

}

(4 调用摄像头操作

+ (MKMapCamera *)cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)coord

fromEyeCoordinate:(CLLocationCoordinate2D)cameraPosition

eyeAltitude:(CLLocationDistance)eyeAltitude;

(5  设置动画效果:比如地理位置的转移,先从上的转移,然后再从上到下

   - (void)mapView:(MKMapView *)mapView didChangeRegionAnimated:(BOOL)animated;

3、MKLocalSearch 搜索

(1 搜索

MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];

request.naturalLanguageQuery = @“Ike’s”;

request.region = ...;

MKLocalSearch *search = [[MKLocalSearch alloc] initWithRequest:request];

[search startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {  // 得到一个MKMapItem 数组,里面还包含MKPlacemark  }];

(2 在地图APP中打开

- (BOOL)openInMapsWithLaunchOptions:(NSDictionary *)options;

4、MKDirections 路线

OC开发_Storyboard——MapKit

三、Embed Segue 
      Container View