更新时间:2022-12-30 13:18:45
在 didUpdateToLocation
写的东西像
AddressAnnotation *myAnnotation = [[AddressAnnotation alloc] initWithCoordinate:currentLocation];
myAnnotation.title = @"You are here";
[self.mapView addAnnotation:myAnnotation];
然后
像
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
// try to dequeue an existing pin view first
static NSString* annotationIdentifier = @"annotationIdentifier";
NSString *titlestr = annotation.title;
MKPinAnnotationView* pinView = (MKPinAnnotationView *)
[mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:nil] autorelease];
if (!pinView)
{
// if an existing pin view was not available, create one
// MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
//initWithAnnotation:annotation reuseIdentifier:annotationIdentifier] autorelease];
if([titlestr isEqualToString:@"You are here"])
{
customPinView.pinColor = MKPinAnnotationColorGreen;
NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;");
}
else{
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.selected = TRUE;
NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;");
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(ShowStoreDetail:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
}
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
return customPinView;
}
else
{
pinView.annotation = annotation;
if([titlestr isEqualToString:@"You are here"])
{
customPinView.pinColor = MKPinAnnotationColorPurple;
NSLog(@"customPinView.pinColor = MKPinAnnotationColorGreen;");
}
else{
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.selected = TRUE;
NSLog(@"customPinView.pinColor = MKPinAnnotationColorPurple;");
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(ShowStoreDetail:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
}
}
return pinView;
return nil;
}