iOS 自有地图

//
//  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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值