需要一个MKMapView,作为显示地图。然后还需要使用CLLocationManager,来管理location。
CLLocation,CLLocationCoordinate2D这两个是位置的一些参数,和CLLocationManager配合使用。
MKCoordinateRegion,MKAnnotation,这两个,一个是用来设置mapview的region,一个是用来显示annotation,和mapview一同使用。
该project中,主要掌握几个点
3.初始化地图区域问题
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray*)locations{
CLLocation *location = [locations lastObject];
MKCoordinateRegion region;
float zoomLevel = 4000;
region = MKCoordinateRegionMakeWithDistance(location.coordinate, zoomLevel, zoomLevel);
self.mapView.centerCoordinate = location.coordinate;
[self.mapView setRegion:region animated:YES];
}
如果上述方法,会产生很大的问题,即地图无法移动的问题,因为每个位置的改动,都会运行上述代码,将地图固定在当前位置。
4.kCLErrorDenied 这个错误,一般是定位权限问题,可以在Settings -> General ->Reset中进行
网友评论