Iphone MapView:注釈ピン-異なる色

android-mapview annotations iphone
Iphone MapView:注釈ピン-異なる色

この問題を解決するためのアドバイスをお願いします。

MapViewにピンを表示するためにXMLファイルを取得しています。 別の方法では、地図上の現在の位置を示しています。

-(void)setPOIs {

NSLog(@"insert POIs");

int x = 0;

while (x < [res count]) {

    CLLocationCoordinate2D c;
    NSString *latitude = [[res objectAtIndex:x] objectForKey:@"latitude"];
    NSString *longitude = [[res objectAtIndex:x] objectForKey:@"longitude"];
    c.latitude = [latitude doubleValue];
    c.longitude = [longitude doubleValue];
    GPSAnnotation *annotation = [[GPSAnnotation alloc] initWithCoordinate:c];
    annotation.mTitle=[[res objectAtIndex:x] objectForKey:@"ordiname"];
    annotation.currentPoint = [NSNumber numberWithInt:[[[res objectAtIndex:x] objectForKey:@"tierarztid"] intValue]];
    annotation.currentRow = [res objectAtIndex:x];
    [mapViewOutlet addAnnotation:annotation];
    [annotation release];

    NSLog(@"latitude setPOIs: %@", latitude);
    x++;
}

[self showOwn];

}

-(void)showOwn \ {

CLLocationCoordinate2D c;
c.latitude = location.latitude;
c.longitude = location.longitude;
GPSAnnotation *annotation1 = [[GPSAnnotation alloc] initWithCoordinate:c];
annotation1.mTitle= @"Ihr Standort";
[mapViewOutlet addAnnotation:annotation1];
[annotation1 release];

}

ここにピンを示します:

- (MKAnnotationView *)mapView:(MKMapView *)mapViewOutlet viewForAnnotation:(GPSAnnotation *)annotation {

int postag = 0;
//int row = 0;

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;


    // Set the image for the button
[myDetailButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal];
[myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];


if ([[annotation title] isEqualToString:@"Current Location"]) {
    postag = 99999;
} else {
    postag = [annotation.currentPoint intValue];

}



myDetailButton.tag  = postag;

// Set the button as the callout view
annView.rightCalloutAccessoryView = myDetailButton;

annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);


return annView;

[annView release];

}

現在の位置のカスタム画像を表示したり、開示ボタンを表示しないようにするにはどうすればよいですか?

  2  0


ベストアンサー

ご意見ありがとうございます! 私は単純にifを適応させることで解決しました…​ elseステートメント

- (MKAnnotationView *)mapView:(MKMapView *)mapViewOutlet viewForAnnotation:(GPSAnnotation *)annotation {

int postag = 0;
//int row = 0;

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeCustom];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;


if ([[annotation title] isEqualToString:@"Ihr Standort"]) {
    postag = 99999;
    UIImage *annotationImage = [UIImage imageNamed:@"07-map-marker.png"];
    annView.image = annotationImage;
} else {
    postag = [annotation.currentPoint intValue];
    [myDetailButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal];
    [myDetailButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside];

}



myDetailButton.tag  = postag;

// Set the button as the callout view
annView.rightCalloutAccessoryView = myDetailButton;

annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);


return annView;

[annView release];

}

BR,

ステファン

1


MKPinAnnotationView`を使用する代わりに、 MKAnnotationView`を使用します。 MKPinAnnotationView`は MKAnnotationView`のサブクラスです。 MKPinAnnotationViewはピンのみを表示します。 MKAnnotationViewには、ピンの代わりに別の画像を表示するように設定できる画像プロパティがあります。

公開ボタンを表示しているコード行は、「rightCalloutAccessoryView」命令です。 それを取り除くと、コールアウトの詳細な開示はなくなります。

0


- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id )annotation
{
if ([annotation isKindOfClass:[ParkingSpot class]])
    {
        static NSString* AnnotationIdentifier = @"ParkAnnotationIdentifier";
        MKAnnotationView* annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:ParkAnnotationIdentifier];
        if (!annotationView)
        {
            MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
            annotationView.draggable = NO;
            UIImage *annotationImage = ...your image here
            annotationView.image = annotationImage;
        }
    return annotationView;
    }
}

0


タイトルとURLをコピーしました