博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Map 地图
阅读量:4352 次
发布时间:2019-06-07

本文共 2303 字,大约阅读时间需要 7 分钟。

添加

#import <MapKit/MapKit.h>头文件

倒入

mapkit.framework 库

mapkit.framework是属于ui,可以在故事版上 添加 mkmapview

#import "ViewController.h"#import 
#import
@interface ViewController ()
//监控 MKmapview@property (weak, nonatomic) IBOutlet MKMapView *map;//为了ios 8 中能 弹出 要访问隐私的对话框@property(strong,nonatomic) CLLocationManager *mar;//反地理编码@property(strong,nonatomic)CLGeocoder *geocoder;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; /* MKMapTypeStandard ,标准地图显示 MKMapTypeSatellite,卫星图 MKMapTypeHybrid 卫星+普通 */ self.map.mapType=MKMapTypeStandard; if ( [[UIDevice currentDevice].systemVersion doubleValue]>=8.0) { // CLLocationManager *mar=[[[CLLocationManager alloc]init]; [self.mar requestAlwaysAuthorization]; //手动象用户提示 要访问隐私 self.map.userTrackingMode=MKUserTrackingModeFollow; NSLog(@"ios8"); } else{ NSLog(@"其他"); //成为mapview代理 由于ios7中不会自动找到你自己的位置 } self.map.delegate=self; //设置地图不让旋转 self.map.rotateEnabled=NO; }-(CLLocationManager *)mar{ if (!_mar) { _mar=[[CLLocationManager alloc]init]; } return _mar;}/*每次更新到新用户的位置就会调用 MKMapView 促发事件的控件 MKUserLocation 大头针模型 */-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{ //地图上的蓝色点称为大头针,点击大头针能显示位置// userLocation.title=@"nn";// userLocation.subtitle=@"2222"; [self.geocoder reverseGeocodeLocation:userLocation.location completionHandler:^(NSArray *placemarks, NSError *error) { CLPlacemark *placemark=[placemarks firstObject]; userLocation.title=placemark.name; userLocation.subtitle=placemark.locality; }]; //移动地图到用户所在的位置 [self.map setCenterCoordinate:userLocation.location.coordinate animated:YES]; //设置地图显示的区域 CLLocationCoordinate2D center=userLocation.location.coordinate; //指定经纬度的跨度 MKCoordinateSpan spen=MKCoordinateSpanMake(5, 5); MKCoordinateRegion region=MKCoordinateRegionMake(center, spen); [self.map setRegion:region animated:YES]; }-(CLGeocoder *)geocoder{ if (!_geocoder) { _geocoder=[[CLGeocoder alloc]init]; } return _geocoder;}@end

 

转载于:https://www.cnblogs.com/lizhan1991/p/4898701.html

你可能感兴趣的文章
12.5号
查看>>
lintcode-medium-Binary Tree Zigzag Level Order Traversal
查看>>
logrotate日志切割
查看>>
POJ-3253 Fence Repair 贪心
查看>>
Arraylist集合遍历输出
查看>>
java中的选择结构与循环结构
查看>>
无法将类型“ASP.login_aspx”转换为“System.Web.UI.WebControls.Login”
查看>>
[cocos2dx] lua注册回调到c++
查看>>
(treap)[bzoj3224][洛谷3369][cogs1829]Tyvj 1728 普通平衡树
查看>>
Linux下常用的shell命令记录
查看>>
HTTP 常用 Header 讲解
查看>>
linux分割字符串操作
查看>>
PHP学习2
查看>>
多实例Mysql配置
查看>>
KOA中间件源码解析
查看>>
构建之法阅读笔记03
查看>>
tkinter学习02
查看>>
Mapnik使用postgres中的栅格数据
查看>>
html基本知识
查看>>
IOS手势不识别
查看>>