美文网首页
定位知识的回顾

定位知识的回顾

作者: Rui哥 | 来源:发表于2018-06-26 13:44 被阅读17次

1.定位
CoreLocation框架
CLLocationManager
设置代理
开始定位
代理方法CLLocation对象,Coordinate:latitude longitude

-(CLLocationManager *)locMgr{
    if (!_locMgr) {
        _locMgr = [[CLLocationManager alloc]init];
        _locMgr.delegate = self;
        _locMgr.distanceFilter = kCLDistanceFilterNone;
        _locMgr.desiredAccuracy = kCLLocationAccuracyBest ;
    }
    return _locMgr;
}

 [self.locMgr startUpdatingLocation];

#pragma mark-CLLocationManagerDelegate

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

    CLLocation *location = locations[0];

    [_locMgr stopUpdatingLocation];
}

1.1定位 之 区域监听

  • 设置监听区域
  CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(40, 116);
  CLLocationDistance   distance = 0.01;
  CLRegion *region = [[CLRegion alloc]initCircularRegionWithCenter:coordinate radius:distance identifier:@"MangoHome"];
    
  [self.locMgr startMonitoringForRegion:region];
  • 监听区域的进 出

#pragma mark-CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region{

  [self.locMgr stopMonitoringForRegion:region];
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region{
  [self.locMgr stopMonitoringForRegion:region];
}

2.地理编码,反地理编码
Coordinate -> CLPlaceMarks ->CLPlaceMark -> CLLocation
注意: 在获取CLPlaceMark 中的city 时需要注意,如果是直辖市(adm)时那么city是没有值得

3.地图的基本使用
注意: 如果是在storyboard 中使用mapView 时需要导入 <MKMapkit/MKMapkit.h>框架,否则可能报错

  • 设置地图的类型
  • 设置地图的跟随模式: UserTackingMode
这个设置可以在使用地图是拿到用户的定位(跟踪用户的位置)
self.mapView.userTrackingMode = MKUserTrackingModeFollow;

展示地图时不需要获取用户的位置
self.mapView.userTrackingMode = MKUserTrackingModeNone;

展示地图时获取用户的位置(跟踪)和方向
self.mapView.userTrackingMode = MKUserTrackingModeFollowWithHeading;

  • 设置mapview 的代理,获取用户的定位(MKUserLocation 大头针模型)
  • 大头针 设置标题
MKUserLocation 大头针模型 -> CLLocation --title -- subtitle
  • 设置地图显示的区域与中心位置
setRegion: 设置地图展示的区域(中心点和跨度)
setCenterCoordinate:(设置地图展示的中心点)

相关文章

网友评论

      本文标题:定位知识的回顾

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