1:加入库CoreLocation.framework,MApKit.framework;

2:@property (nonatomic, strong) CLLocationManager *locationManager;

@property (nonatomic, strong) MKMapView *mapView;

@property (nonatomic, strong) CLLocation *checkinLocation;

@property (strong, nonatomic) NSString *currentLatitude; //纬度

@property (strong, nonatomic) NSString *currentLongitude; //经度

- (void)viewDidLoad {

    [super viewDidLoad];

    self.title=@"地图";

    [self initRightBarButton];

    [self setupLocationManager];

    [self setupMapView];

}

-(void)initRightBarButton{

    UIButton* _btnRight = [UIButton buttonWithType:UIButtonTypeCustom];

    [_btnRight setFrame:CGRectMake(0, 0, 39, 34)];

    UIImage *imgNormal = [UIImage imageNamed:@"gpsbtn_dianji"];

    UIImage *imgSelect = [UIImage imageNamed:@"gpsbtn"];

    [_btnRight setBackgroundImage:imgNormal forState:UIControlStateNormal];

    [_btnRight setBackgroundImage:imgSelect forState:UIControlStateSelected];

    _btnRight.showsTouchWhenHighlighted = YES;

    [_btnRight addTarget:self action:@selector(showUserLocation:) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:_btnRight];

    self.navigationItem.rightBarButtonItem = buttonItem;

}

- (void)setupLocationManager{

    _locationManager=[[CLLocationManager alloc]init];

    _locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;

    //每隔多少米定位一次(这里的设置为不论什么的移动)

    _locationManager.distanceFilter=kCLDistanceFilterNone;

    //iOS 8.0以后

    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {

        [self.locationManager requestWhenInUseAuthorization];

        [self.locationManager startUpdatingLocation];

    }

}

- (void)setupMapView{

    _mapView=[[MKMapView alloc]initWithFrame:self.view.bounds];

    [self.view addSubview:_mapView];

    _mapView.delegate=self;

    //用户位置追踪(用户位置追踪用于标记用户当前位置,此时会调用定位服务)

    _mapView.userTrackingMode=MKUserTrackingModeFollowWithHeading;

    _mapView.mapType=MKMapTypeStandard;

    [self initLocationData];

}

- (void)initLocationData{

    NSMutableArray *arr=[[NSMutableArray alloc]init];

    for (int i=0; i<1; i++) {

        CLLocationDegrees lat=[self.currentLatitude  doubleValue];

        CLLocationDegrees longi=[self.currentLongitude doubleValue];

        NSString *lacationName=@"当前位置";

        BasicMapAnnotation *anno=[[BasicMapAnnotation alloc]initWithLatitude:lat andLongitude:longi];

        anno.title=lacationName;

        anno.index=i;

        [arr addObject:anno];

    }

    [_mapView showAnnotations:arr animated:YES];

}

- (void)showUserLocation:(id)sender{

    MKCoordinateSpan span=MKCoordinateSpanMake(0.01, 0.02);

    MKCoordinateRegion region=MKCoordinateRegionMake(_mapView.userLocation.coordinate, span);

    [_mapView setRegion:region animated:YES];

}

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

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

    self.currentLatitude  = [NSString stringWithFormat:@"%.4f",userLocation.location.coordinate.latitude];

    self.currentLongitude = [NSString stringWithFormat:@"%.4f",userLocation.location.coordinate.longitude];

    [self initLocationData];

    //设置地图显示范围(假设不进行区域设置会自己主动显示区域范围并指定当前用户位置为地图中心点)

    //MKCoordinateSpan span=MKCoordinateSpanMake(0.01, 0.01);

    //MKCoordinateRegion region=MKCoordinateRegionMake(_mapView.region.center, span);

    //[_mapView setRegion:region animated:true];

}

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

    if ([annotation isKindOfClass:[BasicMapAnnotation class]]) {

        static NSString *key=@"AnnotationKey";

        MKAnnotationView *annotationView=[_mapView dequeueReusableAnnotationViewWithIdentifier:key];

        BasicMapAnnotation *aa=(BasicMapAnnotation *)annotation;

        if (!annotationView) {

            annotationView=[[MKAnnotationView alloc]initWithAnnotation:aa reuseIdentifier:key];

            CGRect frame=annotationView.frame;

            frame.size.width=14;

            frame.size.height=35;

            annotationView.frame=frame;

            annotationView.canShowCallout=YES;

            UIImageView*imageview=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"地图标注"]];

            imageview.frame=frame;

            [annotationView addSubview:imageview];

        }

        return annotationView;

    }

    return nil;

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}

iOS 系统地图实现及定位的更多相关文章

  1. iOS开发----地图与导航--定位和位置信息获取

    要实现地图.导航功能,往往需要先熟悉定位功能,在iOS中通过Core Location框架进行定位操作.Core Location自身可以单独使用,和地图开发框架MapKit完全是独立的,但是往往地图 ...

  2. IOS系统唤醒微信内置地图

    针对前一篇文章 唤醒微信内置地图 后来发现在IOS系统中运行 唤醒地图会无效的问题.因为在IOS上无法解析这俩个字符串的问题! 需要对经纬度 使用 “parseFloat()”进行转换 返回一个浮点数 ...

  3. 检测iOS系统的定位服务

    [CLLocationManager locationServicesEnabled]检测的是整个iOS系统的位置服务开关

  4. iOS 系统架构

    https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/ ...

  5. iOS原生地图开发详解

    在上一篇博客中:http://my.oschina.net/u/2340880/blog/414760.对iOS中的定位服务进行了详细的介绍与参数说明,在开发中,地位服务往往与地图框架结合使用,这篇博 ...

  6. IOS系统框架

    IOS系统框架:ios架构号MAC OS的基础框架相似:ios扮演底层硬件和应用程序的中介,底层为所有应用程序提供基础服务,高层则包含一些复杂巧妙的技术和服务,并且创建的应用程序不能直接访问硬件. C ...

  7. 苹果iOS系统下检查第三方APP是否安装及跳转启动

    在iOS系统,使用Url Scheme框架在APP间互相跳转和传递数据,本文只介绍如果检测和跳转. Url Scheme框架 如果你想知道ios设备中是否安装QQ这个软件,我们可以通过一个简单方法判断 ...

  8. iOS系统层次架构

    本文转自:http://blog.csdn.net/lxl_815520/article/details/51172917 一,概述 iOS的系统架构分为四个层次:核心操作系统层(Core OS la ...

  9. 认识iOS系统架构

    关于本文: 文章主要介绍iOS系统架构中的四层结构的内容.常用的框架.大致的功能,然后对iOS开发人员的发展提出自己的一些拙见. 一.iOS系统是基于UNIX系统,所有从系统稳定性上来说的确比其他操作 ...

随机推荐

  1. 从乐视和小米“最火电视”之战 看PR传播策略

        今年的双11够热闹.一方面,阿里.京东.国美.苏宁等电商巨头卯足了劲儿.试图在双11期间斗个你死我活,剑拔弩张的气势超过了以往不论什么一场双11:还有一方面.不少硬件厂商.家电企业也来凑双11 ...

  2. 网页爬虫框架jsoup介绍

    序言:在不知道jsoup框架前,因为项目需求.须要定时抓取其它站点上的内容.便想到用HttpClient方式获取指定站点的内容.这样的方法比較笨,就是通过url请求指定站点.依据指定站点返回文本解析. ...

  3. Java专业技能面试问题(不定时更新)

    刚看到园友五月的仓颉<面试感悟----一名3年工作经验的程序员应该具备的技能>感觉很不错,不论是为面试跳槽准备,还是打算深化精进自己的技术都可以参考一下.面向工资编程多少也有点道理,虽然技 ...

  4. Response.Redirect(),Server.Transfer(),Server.Execute()的区别与网站优化

    转 http://blog.csdn.net/dannywj1371/article/details/10213631 1.Response.Redirect():Response.Redirect方 ...

  5. C++头文件一览

    C++头文件一览 C.传统 C++ #include <assert.h> 设定插入点#include <ctype.h> 字符处理#include <errno.h&g ...

  6. 查看md文件

    使用命令将md文件转为html,在浏览器中演示 通过npm安装i5ting_toc 安装好node之后,可以直接使用npm.Windows+R打开运行框,输入cmd,打开命令窗口.连网的情况下,输入如 ...

  7. Sentry: Python 实时日志平台

    Links https://docs.getsentry.com/on-premise/quickstart/ https://docs.getsentry.com/on-premise/server ...

  8. python 一句话输出26个英文字母

    chr(i) # return i character ord(c) # return integer >>> [chr(i) for i in range(97,123)] ['a ...

  9. [C#学习笔记之异步编程模式2]BeginInvoke和EndInvoke方法 (转载)

    为什么要进行异步回调?众所周知,普通方法运行,是单线程的,如果中途有大型操作(如:读取大文件,大批量操作数据库,网络传输等),都会导致方法阻塞,表现在界面上就是,程序卡或者死掉,界面元素不动了,不响应 ...

  10. thinkphp 5 count()方法在控制器,模板中的使用方法

    thinkphp中关于count()方法的使用: 控制器中:echo count($arr)模板中:{$arr | count}模板中if判断语句中 <if condition="co ...