ios-MKMapView苹果地图开发

来源:互联网 发布:武汉矩阵互动面试 编辑:程序博客网 时间:2024/05/02 01:59

ios应用程序中使用Map Kit API开发地图应用程序。 其核心是MKMapView类使用。我们可以设置地图显示方式、控制地图,可以在地图上添加标注。


在Map Kit API中显示地图的视图是MKMapView,它的委托协议是MKMapViewDelegate。Map Kit API使用需要导入MapKit框架。

- (void)initMapView{    m_mapView = [[MKMapView alloc] initWithFrame:CGRectMake(10, 10, 300, 440)];    m_mapView.backgroundColor = [UIColor clearColor];    m_mapView.delegate = self;    m_mapView.showsUserLocation = YES;    m_mapView.mapType = MKMapTypeSatellite;    [m_mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];    [self.view addSubview:m_mapView];    [m_mapView release];        /*     MKMapTypeStandard 标注地图类型。     MKMapTypeSatellite 卫星地图类型。在卫星地图中没有街道名称等信息;     MKMapTypeHybrid 混合地图类型。在混合地图是在卫星地图上标注出街道等信息;     */        /*     MKUserTrackingModeNone 没有用户跟踪模式;     MKUserTrackingModeFollow 可以跟踪用户的位置变化;     MKUserTrackingModeFollowWithHeading 可以跟踪用户的位置和方向变化;     */}

//MKMapViewDelegate- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{    mapView.centerCoordinate = userLocation.location.coordinate;}//如果失败,回调下面的失败方法:
- (void)mapViewDidFailLoadingMap:(MKMapView *)theMapView withError:(NSError *)error{ NSLog(@"error : %@",[error description]);}</span>


0 0
原创粉丝点击