gpt4 book ai didi

ios - MKMapView 为多个 MKPlacemarks 显示相同的标题

转载 作者:行者123 更新时间:2023-11-29 11:16:55 28 4
gpt4 key购买 nike

我有一个 mkmapview,我在上面放置了几个地标图钉,但是我无法让图钉在标注上显示正确的标题,似乎随机显示图钉集合中的标题 map 。有任何想法吗?代码如下:

(void)viewDidLoad {
[super viewDidLoad];

[mapView setDelegate:self];

CLLocationCoordinate2D geos = CLLocationCoordinate2DMake([putInLat doubleValue], [putInLong doubleValue]);
aMarker = [[RNPlaceMark alloc] initWithCoordinate:geos Title:@"Location A"];

CLLocationCoordinate2D geos2 = CLLocationCoordinate2DMake([takeOutLat doubleValue], [takeOutLong doubleValue]);
bMarker = [[RNPlaceMark alloc] initWithCoordinate:geos2 Title:@"Location B"];

NSArray *annots = [[NSArray alloc] initWithObjects:putInMarker, takeOutMarker, nil];
[mapView addAnnotations:annots];

}

(MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id<MKAnnotation>)annotation {
NSString *title = annotation.title;
MKPinAnnotationView *pinView=(MKPinAnnotationView *)[aMapView dequeueReusableAnnotationViewWithIdentifier:title];

if(pinView==nil)
pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:title] autorelease];

if(annotation == aMarker)
[pinView setPinColor:MKPinAnnotationColorGreen];
else if(annotation == bMarker)
[pinView setPinColor:MKPinAnnotationColorRed];

pinView.canShowCallout=YES;
pinView.animatesDrop=YES;


return pinView;
}

最佳答案

我将代码切换为使用 MKPointAnnotation 它工作正常,所以现在看起来......

我在托管 UIMapVIew 的 View 上的 viewDidLoad 方法中执行以下代码:

MKPointAnnotation *myMarker = [[MKPointAnnotation alloc] init];
[myMarker setTitle:@"Hello World"];
CLLocationCoordinate2D geos = CLLocationCoordinate2DMake([myMarkerLat doubleValue], [myMarkerLong doubleValue]);
[myMarker setCoordinate:geos];

NSArray *annots = [[NSArray alloc] initWithObjects:myMarker, nil];
[mapView addAnnotations:annots];

然后我有...

- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id
<MKAnnotation>)annotation
{
NSString *title = annotation.title;
MKPinAnnotationView *pinView=(MKPinAnnotationView *)[aMapView dequeueReusableAnnotationViewWithIdentifier:title];

if(pinView==nil)
pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:title] autorelease];

//If you want to change the color of the pin you can with something like...
//if(annotation == whatEverInstanceOfAMarkerIWantToKeep)
// [pinView setPinColor:MKPinAnnotationColorGreen];

pinView.canShowCallout=YES;
pinView.animatesDrop=YES;


return pinView;

关于ios - MKMapView 为多个 MKPlacemarks 显示相同的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9042746/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com