Create a title for annotation from MKLocalSearch

三世轮回 提交于 2019-12-06 15:13:43

Since the title of the item.placemark cannot be directly modified, you'll need to create a custom annotation or MKPointAnnotation using the values from item.placemark.

(The comment in the code above the addObject line mentions an "MKPinAnnotation" but I think it was meant to say "MKPointAnnotation".)

The example below uses the simple option of using the pre-defined MKPointAnnotation class provided by the SDK for creating your own, simple annotations.

Replace this line:

[annotations addObject:item.placemark];

with these:

MKPlacemark *pm = item.placemark;

MKPointAnnotation *ann = [[MKPointAnnotation alloc] init];
ann.coordinate = pm.coordinate;
ann.title = pm.name;    //or whatever you want
//ann.subtitle = @"optional subtitle here";

[annotations addObject:ann];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!