地图Map

作者: rainbow_H | 来源:发表于2018-06-13 15:40 被阅读0次

- (void)viewDidLoad {

    [super viewDidLoad];

    /**创建地图*/

    [self creatMap];

    /**定位当前*/  // 模拟器上无法定位

    [self selfLocation];

}

#pragma mark定位自己

- (void)selfLocation{

    // 创建定位对象

    _locationManager = [[CLLocationManager alloc]init];

    // 设置定位属性

    _locationManager.desiredAccuracy = kCLLocationAccuracyBest;

    // 设置定位更新距离

    _locationManager.distanceFilter = 10.0;

    // 绑定定位委托

    _locationManager.delegate = self;

    //取出当前应用的定位服务状态(枚举值)

    CLAuthorizationStatus status =[CLLocationManager authorizationStatus];

    //如果未授权则请求

    if(status==kCLAuthorizationStatusNotDetermined) {

        [_locationManager requestAlwaysAuthorization];

    }

    // 开始定位

    [_locationManager startUpdatingLocation];

}

#pragma mark CLLocationManagerDelegate

// 定位后的返回结果

- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray *)locations{

    //locations数组中存储的是CLLocation

    //遍历数组取出坐标--》如果不需要也可以不遍历

    CLLocation*location =[locationsfirstObject];

     MKCoordinateRegion region =MKCoordinateRegionMake(location.coordinate, MKCoordinateSpanMake(0.01,0.01));

    [_mapView setRegion:region animated:YES];

    // 创建大头针

    MKPointAnnotation *point = [[MKPointAnnotation alloc]init];

    // 设置经纬度

    point.coordinate= location.coordinate;

    // 设置主标题

    point.title = @"The location of the I";

    // 设置副标题

    point.subtitle=@"Hello Map";

    // 将大头针添加到地图上

    [_mapViewaddAnnotation:point];

}

#pragma mark创建地图

-(void)creatMap{

    // 实例化

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

    // 是否可以缩放

    _mapView.zoomEnabled = YES;

    // 是否可以滚动

    _mapView.scrollEnabled = YES;

    // 是否可以旋转

    _mapView.rotateEnabled = YES;

    // 是否显示3D

    _mapView.pitchEnabled = YES;

    // 是否显示指南针

     _mapView.showsCompass = YES;

     // 是否显示比例尺

     _mapView.showsScale = YES;

     // 是否显示交通

    _mapView.showsTraffic = YES;

     // 是否显示建筑物

     _mapView.showsBuildings = YES;

     //绑定委托

    _mapView.delegate=self;

    //添加到界面

    [self.view addSubview:_mapView];

    //添加手势

    UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

     //添加到地图上

     [_mapView addGestureRecognizer:longPress];

    //创建UISegmentedControl

    NSArray*mapTypeArray =@[@"标准",@"卫星地图",@"混合"];

    UISegmentedControl *segment =[[UISegmentedControl alloc] initWithItems:mapTypeArray];

     segment.frame=CGRectMake(50,50,300,50);

     [_mapViewaddSubview:segment];

    segment.selectedSegmentIndex=0;

}

- (void)longPress:(UILongPressGestureRecognizer *)sender{

    // 判断是否长按

    if (sender.state != UIGestureRecognizerStateBegan) {

        return;

    }

}

相关文章

  • zabbixApi4j-Map

    Map map.create: 创建新地图map.delete: 删除地图map.exists: 检查地图是否存在...

  • 4种常见用户体验地图速览

    摘要:移情地图(Empathy map),客户旅程地图(customer journey map),体验地图(ex...

  • 接入amap_map_fluttify 0.25.0 高德地图社

    amap_map_fluttify 0.25.0高德地图 地图组件 Flutter插件 第三方库 amap_map...

  • 高德地图 JS API 学习摘要2

    自定义地图 指定Map.mapStyle属性,实现自定义样式地图。 使用Map.setMapStyle()方法,加...

  • 微信小程序地图功能

    想要实现地图功能,首先先来说说显示地图 map,该组件是原生组件。map组件官方文档 第一步:显示地图 在对地图进...

  • uni-app map地图组件应用

    map地图组件使用时直接在template中使用标签,标签中可嵌套map属性 map最常用到...

  • 地图Map

    - (void)viewDidLoad { [super viewDidLoad]; /**创建地图*/ ...

  • Map地图

    MapKit:用于地图展示 CoreLocation:用于地理定位 CoreLocation框架的使用 CLLoc...

  • Map地图

    #import "ViewController.h" #import @interface ViewControl...

  • 地图map

    在页面中引入地图 首先要注册百度地图的开发者账号然后开始创建密钥 新建一个index.html 然后引用百度地图A...

网友评论

      本文标题:地图Map

      本文链接:https://www.haomeiwen.com/subject/qcwjeftx.html