【发布时间】:2010-12-01 13:20:36
【问题描述】:
在地图视图中,我正在显示当前用户位置。单击图钉显示“当前位置”。我想将其更改为“我的当前位置”。我怎样才能改变它。 我还想在计时器中更改当前用户位置引脚颜色。就像每一秒它应该在绿色、紫色和红色之间改变它的颜色。有可能做到吗?
我正在使用地图工具包的显示默认位置,然后如下操作注释图钉颜色:
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation{
static NSString *AnnotationViewID = @"annotationViewID";
SolarAnnotationView* annotationView = (SolarAnnotationView*)[map dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if(annotationView == nil)
{
if([self CLLocationCoordinate2DEquals:mapView.userLocation.location.coordinate withSecondCoordinate:[annotation coordinate]]) //Show current location with green pin
{
annotationView = [[SolarAnnotationView alloc] initWithAnnotation:annotation];
annotationView.delegate = self;
[annotationView setPinColor:MKPinAnnotationColorGreen];
}
else
{
annotationView = [[SolarAnnotationView alloc] initWithAnnotation:annotation];
annotationView.delegate = self;
}
}
return annotationView;
}
- (BOOL) CLLocationCoordinate2DEquals:(const CLLocationCoordinate2D)lhs withSecondCoordinate:(const CLLocationCoordinate2D) rhs{
const CLLocationDegrees DELTA = 0.001;
return fabs(lhs.latitude - rhs.latitude) <= DELTA && fabs(lhs.longitude - rhs.longitude) <= DELTA;
}
【问题讨论】:
-
显示当前位置的显示方式。您是在使用地图视图的 showsUserLocation 属性来获取默认蓝点还是创建自定义图钉?展示如何添加注释和 viewForAnnotation 方法。