-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