Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在地图注释视图上设置标题和副标题_Ios_Mapkit_Mkannotation_Mkannotationview - Fatal编程技术网

Ios 在地图注释视图上设置标题和副标题

Ios 在地图注释视图上设置标题和副标题,ios,mapkit,mkannotation,mkannotationview,Ios,Mapkit,Mkannotation,Mkannotationview,我回答了这个问题:-为邮政编码创建地图注释,而不是直接使用long/lat值 CLPlacemark *topResult = [placemarks objectAtIndex:0]; MKPlacemark *placemark = [[MKPlacemark alloc] placemark.title = self.business.businessName; placemark.subtitle = self.business.phoneNumber; 这很好,但是我想设置anno

我回答了这个问题:-为邮政编码创建地图注释,而不是直接使用long/lat值

CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] 
placemark.title = self.business.businessName;
placemark.subtitle = self.business.phoneNumber;
这很好,但是我想设置anno的标题和副标题

CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] 
placemark.title = self.business.businessName;
placemark.subtitle = self.business.phoneNumber;

这不起作用,因为标题和副标题是只读的。如何更改上述内容,以便设置标题和副标题?

使用
MKPointAnnotation

CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] 
placemark.title = self.business.businessName;
placemark.subtitle = self.business.phoneNumber;
示例代码:

CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] 
placemark.title = self.business.businessName;
placemark.subtitle = self.business.phoneNumber;
CLPlacemark *topresult = [placemarks objectAtIndex:0];
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = topresult.location.coordinate;
annotation.title = self.business.businessName;
annotation.subtitle = self.business.phoneNumber;
[self.mapView addAnnotation:annotation];

您可以尝试下面的代码。这可能对你有帮助

CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] 
placemark.title = self.business.businessName;
placemark.subtitle = self.business.phoneNumber;
//set the title if we got any placemarks...
if (placemark.count > 0)
{
    CLPlacemark *topResult = [placemark objectAtIndex:0];
    annTitle = [NSString stringWithFormat:@"%@ %@ %@ %@", topResult.country, topResult.locality, topResult.subLocality, topResult.thoroughfare];
}

//now create the annotation...
MapAnnotation *toAdd = [[MapAnnotation alloc]init];

toAdd.coordinate = touchMapCoordinate;
toAdd.title = @"Address";
toAdd.subtitle = @"Sub Address";

[self.map addAnnotation:toAdd];

请参考以下内容以了解您的查询。您不需要“必须”专门使用MKPointAnnotation——只需要一些实现MKAnnotation并具有可设置标题和副标题的类(类似于MKPointAnnotation,但您可以创建自己的类)。另外,
locationManager.location.coordinate
应该是
topResult.location.coordinate
@Anna:True。更新。谢谢