如何在地图工具包中实现默认用户位置及自定义年度视图的显示功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计286个文字,预计阅读时间需要2分钟。
我正在使用地图工具,并显示自定义注释视图。一个是car+Image,另一个是user+Image(作为用户的当前位置)。现在我想显示map kit提供的当前用户位置默认值,但无法显示它。如何在地图组件中显示当前位置?
mapView.showsUserLocation = YES;
要显示自定义注释,请在地图视图注记上设置图像属性
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { // check for nil annotation, dequeue / reuse annotation // to avoid over riding the user location default image ( blue dot ) if ( mapView.UserLocation == annotation ) { return nil; // display default image } MKAnnotationView* pin = (MKAnnotationView*) [mapView dequeueReusableAnnotationViewWithIdentifier: PIN_RECYCLE_ID]; if ( pin == nil ) { pin = [(MKAnnotationView*) [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: PIN_RECYCLE_ID] autorelease] ; pin.canShowCallout = YES; } else { [pin setAnnotation: annotation]; } pin.image = [UIImage imageNamed:@"car-image.png"]; return pin; }
本文共计286个文字,预计阅读时间需要2分钟。
我正在使用地图工具,并显示自定义注释视图。一个是car+Image,另一个是user+Image(作为用户的当前位置)。现在我想显示map kit提供的当前用户位置默认值,但无法显示它。如何在地图组件中显示当前位置?
mapView.showsUserLocation = YES;
要显示自定义注释,请在地图视图注记上设置图像属性
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { // check for nil annotation, dequeue / reuse annotation // to avoid over riding the user location default image ( blue dot ) if ( mapView.UserLocation == annotation ) { return nil; // display default image } MKAnnotationView* pin = (MKAnnotationView*) [mapView dequeueReusableAnnotationViewWithIdentifier: PIN_RECYCLE_ID]; if ( pin == nil ) { pin = [(MKAnnotationView*) [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: PIN_RECYCLE_ID] autorelease] ; pin.canShowCallout = YES; } else { [pin setAnnotation: annotation]; } pin.image = [UIImage imageNamed:@"car-image.png"]; return pin; }

