-2
我展示一些定制注释中的MapView使用以下代码,如何在MKMapView中显示用户位置以及自定义注释?
for(int i=0;i<[[st.defaultmaparray objectAtIndex:0] count];i++)
{
CLLocationCoordinate2D location;
location.latitude = [[[st.defaultmaparray objectAtIndex:13] objectAtIndex:i] floatValue];
location.longitude = [[[st.defaultmaparray objectAtIndex:14] objectAtIndex:i] floatValue];
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta = 0.05;
span.longitudeDelta = 0.05;
region.span = span;
region.center = location;
[latlongarray addObject:[NSString stringWithFormat:@"%f,%f",location.latitude,location.longitude]];
[self.mapView regionThatFits:region];
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = [[st.defaultmaparray objectAtIndex:3] objectAtIndex:i];
ann.subtitle = [NSString stringWithFormat:@"%@,%@,%@",[[st.defaultmaparray objectAtIndex:4] objectAtIndex:i],[[st.defaultmaparray objectAtIndex:9] objectAtIndex:i],[[st.defaultmaparray objectAtIndex:10] objectAtIndex:i]];
ann.coordinate = region.center;
[self.mapView addAnnotation:ann];
//[self.mapView selectAnnotation:ann animated:YES];
}
及其viewforannotation方法如下,
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
int imageint = [latlongarray indexOfObject:[NSString stringWithFormat:@"%f,%f",annotation.coordinate.latitude,annotation.coordinate.longitude]];
static NSString *SFAnnotationIdentifier = @"SFAnnotationIdentifier";
if ([annotation isKindOfClass:[MKUserLocation class]])
{
NSLog(@" view for UL ");
return nil;
}
else
{
MKPinAnnotationView *customPinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:SFAnnotationIdentifier];
customPinView.pinColor = MKPinAnnotationColorRed;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
AsyncImageView *async = [[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
[async loadImageFromURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[st.defaultmaparray objectAtIndex:5] objectAtIndex:imageint]]];
async.backgroundColor=[UIColor whitecolor];
[sfIconView addSubview:async];
sfIconView.frame = CGRectMake(-15, 0, 50, 50);
[customPinView addSubview:async];
return customPinView;
}
return nil;
}
上面的代码工作正常,并输出是像下面,
不过,现在我需要与这些一起显示用户的当前位置自定义注释。用户的位置应像显示与它周围的圆形波像下面的图像的蓝色圆点标记,
如何添加?请指教。
这个简单的事情,我错过了,感谢回忆。 – NAZIK