Mapkit地图显示

导入头文件“MapKit.h”

1、MKMapView

能够显示ios自带的地图(国内默认为高德地图)

  • mapType : 地图的显示模式
    • MKMapTypeStandard:标准模式
    • MKMapTypeSatellite:卫星模式
    • MKMapTypeHybrid:混合模式
    • MKMapTypeSatelliteFlyover:3D立体卫星
    • MKMapTypeHybridFlyover:3D立体混合
  • centerCoordinate:中心位置坐标
  • zoomEnabled:是否允许缩放
  • scrollEnabled:是否允许平移
  • showsCompass:显示指南针
  • showsUserLocation:显示当前位置

初始化代码

    MKMapView *mapView = [[MKMapView alloc] init]
    mapView.mapType = MKMapTypeStandard;
    mapView.delegate = self;
    
//    self.mapView.zoomEnabled = NO;
    // 需要用到定位
    CLLocationManager *lM = [[CLLocationManager alloc] init];
    [lM requestAlwaysAuthorization];
//    self.mapView.showsCompass = YES;
    
    self.mapView.showsUserLocation = YES;

代理方法:

/**
 *  更新到用户位置后调用
 */
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    // 设置地图显示中心
    [mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
    
    // 设置地图显示区域
    MKCoordinateSpan span = MKCoordinateSpanMake(0.01, 0.01);
    MKCoordinateRegion region = MKCoordinateRegionMake(userLocation.location.coordinate, span);
    [mapView setRegion:region animated:YES];
}

效果如下:

地图自动定位效果.gif
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容