iPhone map 查看: Annotation Pin - Different Color

标签 iphone annotations android-mapview

我请求您提供解决此问题的建议:

我正在获取一个 XML 文件以在我的 MapView 上显示 Pin 图。在另一种方法中,我在 map 上显示我当前的位置:

-(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];

}

如何才能显示当前位置的自定义图像 - 和/或不显示披露按钮?

最佳答案

感谢您的反馈!我通过简单地调整 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,

斯特凡

关于iPhone map 查看: Annotation Pin - Different Color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5330788/

相关文章:

iphone - 将 Facebook 添加到应用 Xcode

ios - 在 MKMapView 上尝试多个注释时出现 SIGABRT 错误

flash - 有关如何创建和显示youtube批注的技术说明?

iphone - 使用特定的纬度和经度 Iphone 初始化 Mapkit

android - MapView 泄漏 Activity (没有定位服务)

iphone - iOS 的复杂 JSON 响应

iphone - NSUserDefaults 与 NSKeyedArchiver

iphone - Objective C,滚动菜单缩略图

java - 使用注释和使用 web.xml 有什么区别?

android - 添加许多 Overlay 后 MapView 平移和缩放速度很慢