如何以编程方式选择地图大头针

时间:2023-02-05 20:26:06

I am new to Maps Concept.

我是地图概念的新手。

Please find the attached image once.

请查收附件图片。

如何以编程方式选择地图大头针

when i click the "pin" i am getting message says "Admire your smile" or any text..... Now i want like... when we select the table view, i need to raise that message for that pin(with out user interaction for that pin)...

当我点击“pin”时,我得到的信息是“赞美你的微笑”或任何文字……现在我要像…当我们选择table视图时,我需要为那个大头针发出那个消息(没有那个大头针的用户交互)……

I am using below code for This maps and pins.

我正在使用下面的代码为这个地图和大头针。

    -(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
customLocation.latitude=[casesobjc.latitude_string doubleValue];
        customLocation.longitude=[casesobjc.longitude_string doubleValue];
 MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:casesobjc.locationForMap_string andCoordinate:customLocation];
[mapView addAnnotation:newAnnotation];
}
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation {
 MKPinAnnotationView *pin = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier: @"annotation_ID"];
if (pin == nil) {
        pin = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"annotation_ID"];
    } else {
        pin.annotation = annotation;
    }
    pin.pinColor = MKPinAnnotationColorPurple;
    pin.animatesDrop = YES;
    pin.canShowCallout=YES;
return pin;
}

Now i will show all the pins once like below.

现在我将展示所有的大头针如下所示。

如何以编程方式选择地图大头针

How to do When we click on table view i need to show the title for that pin like how we show when we select a pin?

当我们点击表格视图时我需要显示那个大头针的标题就像我们选择大头针时显示的一样?

Thanks in Advance

谢谢提前

2 个解决方案

#1


25  

The method that you are looking for is selectAnnotation:.

您正在寻找的方法是selectAnnotation:。

In your didSelectRowAtIndexPath, you have to find the annotation associated with the table row.

在didSelectRowAtIndexPath中,必须找到与表行关联的注释。

Once you find it, you can tell it, to select it by using:

一旦你找到它,你就可以告诉它,通过使用:

[mapView selectAnnotation:foundAnnotation animated:YES];

#2


2  

The same as the Objective C answer, in your tableview you have a list of annotations. In Swift in the didSelectRow:

与Objective C答案相同,在tableview中有一个注解列表。在didSelectRow的Swift中:

For Swift 4:

为迅速4:

// annotations would be the array of annotations - change to your required data sets name
let selectedAnnotation = annotations[indexPath.row]
self.mapView.selectAnnotation(selectedAnnotation, animated: true)

Short and simple.

短而简单。

#1


25  

The method that you are looking for is selectAnnotation:.

您正在寻找的方法是selectAnnotation:。

In your didSelectRowAtIndexPath, you have to find the annotation associated with the table row.

在didSelectRowAtIndexPath中,必须找到与表行关联的注释。

Once you find it, you can tell it, to select it by using:

一旦你找到它,你就可以告诉它,通过使用:

[mapView selectAnnotation:foundAnnotation animated:YES];

#2


2  

The same as the Objective C answer, in your tableview you have a list of annotations. In Swift in the didSelectRow:

与Objective C答案相同,在tableview中有一个注解列表。在didSelectRow的Swift中:

For Swift 4:

为迅速4:

// annotations would be the array of annotations - change to your required data sets name
let selectedAnnotation = annotations[indexPath.row]
self.mapView.selectAnnotation(selectedAnnotation, animated: true)

Short and simple.

短而简单。