Ios 在地图注释视图上设置标题和副标题
我回答了这个问题:-为邮政编码创建地图注释,而不是直接使用long/lat值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
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。更新。谢谢