//
// ViewController.m
// MapView
//
// Created by lcy on 16/1/14.
// Copyright (c) 2016年 lcy. All rights reserved.
//
#import "ViewController.h"
#import <MapKit/MapKit.h>
//MKMapView
//CLLocationManager
//定位
//搜索
@interface ViewController () <CLLocationManagerDelegate>
@property (nonatomic,strong) MKMapView *mapView;
@property (nonatomic,strong) CLLocationManager *locationManager;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
//类型
self.mapView.mapType = MKMapTypeStandard;
/*
typedef struct {
CLLocationDegrees latitude; 纬度
CLLocationDegrees longitude; 经度
} CLLocationCoordinate2D;
//在经纬度上的放大或者缩小的比例,值越小,地图放大程度越大
typedef struct {
CLLocationDegrees latitudeDelta;
CLLocationDegrees longitudeDelta;
} MKCoordinateSpan;
*/
//经纬度 22.533367,113.935404
[self.mapView setRegion:MKCoordinateRegionMake(CLLocationCoordinate2DMake(22.533367, 113.935404), MKCoordinateSpanMake(0.1, 0.1)) animated:YES];
[self.view addSubview:self.mapView];
self.locationManager = [[CLLocationManager alloc] init];
//设置代理
self.locationManager.delegate = self;
//精确度
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
//设置位置更新的频率 米
self.locationManager.distanceFilter = 10.0;
//定位 ----> 地图的属性 ---->
self.mapView.showsUserLocation = YES;
//ios8
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
//获取定位的权限
//NSLocationAlwaysUsageDescription plist
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
//CLLocation
CLLocation *location = locations[0];
[self.mapView setRegion:MKCoordinateRegionMake(location.coordinate, MKCoordinateSpanMake(0.1, 0.1)) animated:YES];
[self.locationManager stopUpdatingLocation];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end