1.添加MapKit.framework框架 ,在plist中添加字段,用于,获取用户当前位置设置

NSLocationAlwaysUsageDescription

2.代码

#import "ViewController.h"

#import <MapKit/MapKit.h>

@interface ViewController ()<MKMapViewDelegate>

@property (weak, nonatomic) IBOutlet MKMapView *mapKit;

//位置信息

@property(nonatomic,strong)CLLocation*location;

//地理编码对象

@property(nonatomic,strong)CLGeocoder*geocide;

@property(nonatomic,strong)CLLocationManager*manager;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

//地图显示的类型

//MKMapTypeStandard:标准类型

//MKMapTypeSatellite:卫星模型

//MKMapTypeHybrid:混合模型

self.mapKit.mapType=MKMapTypeStandard;

//    ios8中追踪用户位置

if([[UIDevice currentDevice].systemVersion doubleValue]>8.0)

{

self.manager =[[CLLocationManager alloc]init];

[self.manager requestAlwaysAuthorization];

}

//设置不允许地图旋转

self.mapKit.rotateEnabled=NO;

self.mapKit.delegate=self;

//设置mapKit获取用户位置的方式

//    MKUserTrackingModeNone 不追踪

//    MKUserTrackingModeFollow 追踪

//    MKUserTrackingModeFollowWithHeading 追踪并获取用户的方向

self.mapKit.userTrackingMode=MKUserTrackingModeFollowWithHeading;

}

-(CLGeocoder*)geocide

{

if (_geocide==nil) {

_geocide=[[CLGeocoder alloc]init];

}

return _geocide;

}

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

{

//利用地理编码获取位置,设置标题

[self.geocide reverseGeocodeLocation:userLocation.location completionHandler:^(NSArray *placemarks, NSError *error) {

CLPlacemark *mark=[placemarks firstObject];

userLocation.title=mark.name;

userLocation.subtitle=mark.locality;

}];

//利用地图当前的位置设置显示的区域

CLLocationCoordinate2D center=userLocation.location.coordinate;

//指定纬度的跨度

MKCoordinateSpan span=MKCoordinateSpanMake(0.009310,0.007812);

//指定显示区域的中

MKCoordinateRegion region=MKCoordinateRegionMake(center, span);

//设置显示区域

[self .mapKit setRegion:region];

}

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

{

//地图区域改变完成

NSLog(@"%f,%f",self.mapKit.region.span.latitudeDelta,self.mapKit.region.span.longitudeDelta);

}

@end

MapKit的使用显示当前位置的更多相关文章

  1. Jquery 实现点击一个页面跳转后在另外一个页面显示指定位置

    <script> $(function(){ var isTarget = '<?php echo $_GET['target']; ?>'; if (isTarget != ...

  2. ios map 显示用户位置

    昨天遇到个奇怪的问题,用户的位置在地图中死活不显示,showUserLocation也设置了,最后发现是因为实现了 mapView protocol中的一个方法: -(MKAnnotationView ...

  3. iOS开发中获取视图在屏幕上显示的位置

    在iOS开发中,我们会经常遇到一个问题,例如,点击一个按钮,弹出一个遮罩层,上面显示一个弹框,弹框显示的位置在按钮附近.如果这个按钮的位置相对于屏幕边缘的距离是固定的,那就容易了,可以直接写死位置.可 ...

  4. ScrollView嵌套ListView、GridView,进入页面显示的位置并不是在最顶部,而是在中间部分问题

    在Android项目的开发中,经常会遇到一些布局,可能需要在ScrollView中嵌套ListView或.GridView来实现, 是在使用的过程总又遇到了一个新的问题,就是如果在ScrollView ...

  5. [游戏模版4] Win32 显示鼠标位置

    >_<:use MOUSE_MOVE message refresh the position information. >_<:use LOWORD(lParam) get ...

  6. 通过百度地图API显示当前位置在地图上(图标显示)--第三方开源--百度地图(二)

    1.下载百度地图的demo,下载地址:http://lbsyun.baidu.com/sdk/download?selected=mapsdk_basicmap,mapsdk_searchfuncti ...

  7. 【Android Developers Training】 105. 显示一个位置地址

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  8. Android使用百度地图定位并显示手机位置后使用前置摄像头“偷拍”

    今天老板让我验证一下技术可行性,记录下来. 需求 :定位手机的位置并在百度地图上显示,得到位置后使用前置摄像头进行抓拍 拿到这个需求后,对于摄像头的使用不太熟悉,于是我先做了定位手机并在百度地图上显示 ...

  9. Visual studio之C# 重新定义Messbox的显示窗口位置

    背景 当前做的APP需要新建一个设置窗口,该设置窗口会出现在靠近屏幕边缘位置,但主窗口铺满屏幕,设置窗口会弹出一些讯息,但默认情况下Messagebox窗口会居中于主窗口,这不太符合要求,正常应该居中 ...

随机推荐

  1. dubbo main方法启动

    public static void main(String[] args) { com.alibaba.dubbo.container.Main.main(args); } 以上就可以简单本地启动了

  2. ansible操作远程服务器报Error: ansible requires the stdlib json or simplejson module, neither was found!

    通过ansible执行远程命令时报如下异常: Error: ansible requires the stdlib json or simplejson module, neither was fou ...

  3. 解读Unity中的CG编写Shader系列五(理论知识)

    转自 http://www.itnose.net/detail/6098474.html 经过前面的系列文章中的三个例子,尽管代码简单,但是我想应该还有些地方没有100%弄明白,我们现在得回过头来补充 ...

  4. C# 读写十六进制bin 文件

    读一个十六进制的bin文件,在bin文件添加四行头,生成新的bin文件.bin文件可以用vs打开查看. using System; using System.Collections.Generic; ...

  5. Log4perl 的使用

    Perl 使用Log4perl 首先下载log4 module : http://search.cpan.org/CPAN/authors/id/M/MS/MSCHILLI/Log-Log4perl- ...

  6. Git-windows安装包

    下载地址 http://192.168.168.230/sw-search-sp/soft/4e/30195/Git-2.7.2-32-bit_setup.1457942412.exe 来自为知笔记( ...

  7. PHP工厂模式的研究

    工厂方法模式 把 创造者类 和要生产的 产品类 分离.创建者是一个工厂类,其定义了产品生产的类方法.一般情况下,创建者类的每个子类实例化一个相应的产品子类. 下面是单个产品的实现代码: <?ph ...

  8. August 29th 2016 Week 36th Monday

    Every has the capital to dream. 每个人都有做梦的本钱. Your vision, our mission. That is an advertisment of UMo ...

  9. August 18th 2016 Week 34th Thursday

    Comedy is acting out optimism. 喜剧就是将乐观演绎出来. Being optimistic or pessimistic, that is all about your ...

  10. July 9th, Week 28th Saturday, 2016

    Every cloud has a silver lining. 山穷水尽疑无路,柳暗花明又一村. Every cloud has a silver lining, that just because ...