1

1-次のコードを使用していますが、カスタムピンにデフォルトのロケーションピンのようにバブルが表示されません。2-ロケーションピンをカスタマイズして、色をデフォルトの青から赤に変更したり、アニメーションの円の半径を大きくしたりする方法はありますか?

-(void) showMarkers
{
    [self.mapView removeAnnotations:[self.mapView annotations]];
    for (int i = 0 ; i < 1;  i ++)
    {
        MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];

        Players *player = [self.playersArray objectAtIndex:i];

        annotationPoint.coordinate = CLLocationCoordinate2DMake([player.latitude doubleValue], [player.longitude doubleValue]);
        annotationPoint.title = player.name;
        annotationPoint.subtitle = [NSString stringWithFormat:@"Level %@", player.level ];
        [self.mapView addAnnotation:annotationPoint];
        MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(annotationPoint.coordinate, 1500, 1500);
        MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:viewRegion];
        [self.mapView setRegion:adjustedRegion animated:YES];

    }
}

- (void)map:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    self.mapView.centerCoordinate = userLocation.location.coordinate;
    myLocation = userLocation;
}

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    if ([[annotation title] isEqualToString:@"Current Location"] )
    {
        return nil;
    }

    MKAnnotationView *annView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"players"];
    annView.image = [UIImage imageNamed:@"marker.png"];
    annView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    annView.canShowCallout = YES;
    annView.enabled = YES;
    [annView setUserInteractionEnabled:YES];

    return  annView;
}
4

1 に答える 1

0

最近アプリで、デフォルトのピンの代わりにバブルを表示するためにカスタム画像を使用しました。使用したコードを以下に掲載します。ご覧ください。多分それは助けになるでしょう。

(MKAnnotationView *) mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation>) annotation{

Annotation *annotationInst = (Annotation*)annotation;


MKAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
    static NSString *defaultPinID = @"mypin";
    pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];

    if ( pinView == nil ){
        pinView = [[[MKAnnotationView alloc]
                   initWithAnnotation:annotation reuseIdentifier:defaultPinID]autorelease];

    }        

    pinView.canShowCallout = YES;
    pinView.image = [UIImage imageNamed:@"pin.png"];

    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinView.rightCalloutAccessoryView = rightButton; 
}
else {
    [mapView.userLocation setTitle:@"You are here"];
}
return pinView;
}

コールアウト アクセサリ ボタンをクリックして取得するには:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
Annotation *tappedAnnotation =  view.annotation;
CLLocationCoordinate2D tappedLocation = [tappedAnnotation coordinate];  

}

于 2013-01-07T15:13:13.780 に答える