我得到了 MKLocalSearch
的结果,它包括类似...
{
address = {
formattedAddressLine = (
"Marton Road",
Middlesbrough,
TS1,
England
);
structuredAddress = {
administrativeArea = England;
areaOfInterest = (
"Great Britain"
);
country = "United Kingdom";
countryCode = GB;
fullThoroughfare = "Marton Road";
geoId = (
);
locality = Middlesbrough;
postCode = TS1;
subAdministrativeArea = Middlesbrough;
thoroughfare = "Marton Road";
};
};
addressGeocodeAccuracy = 0;
business = (
{
UID = 9301704419119613323;
URL = "http://www.cineworld.co.uk";
attribution = (
{
attributionURLs = (
"yelp5.3:///biz/cineworld-middlesbrough",
"yelp4:///biz/cineworld-middlesbrough",
"yelp:///biz/cineworld-middlesbrough",
"http://yelp.com/biz/cineworld-middlesbrough"
);
sourceIdentifier = "com.yelp";
sourceVersion = 1;
}
);
canBeCorrectedByBusinessOwner = 1;
name = Cineworld;
source = (
{
"source_id" = "b2LOPag6ha6845__dgXehw";
"source_name" = yelp;
},
{
"source_id" = 6670;
"source_name" = tribune;
},
{
"source_id" = 2000000103009680;
"source_name" = "acxiom_intl";
},
{
"source_id" = "cineworld-middlesbrough";
"source_name" = "yelp_alias";
}
);
"star_rating" = (
0
);
telephone = "+448712002000";
}
);
center = {
lat = "54.57633773904653";
lng = "-1.228197113614671";
};
inputLanguage = en;
localSearchProviderID = 9902;
mapRegion = {
eastLng = "-1.224891596539819";
northLat = "54.57545000290778";
southLat = "54.5738619816233";
westLng = "-1.227631256834202";
};
name = Cineworld;
type = 57;
}
现在,当我将它添加到我的 map 时...
id <MKAnnotation> annotation = mapItem.placemark;
[self.mapView addAnnotation:annotation];
它添加了一个图钉,当我点击它时,它会显示“Marton Road”,但我希望它显示“Cineworld”。
我发现很难找到任何有关将内容从 MKMapItem
中取出并放入 MKPlacemark
的信息。
如果我尝试在地标中使用mapItem.name
,那么它们都会显示“美国”。
知道如何从中获得一些更有用的信息吗?
最佳答案
MKPlacemark
返回其 title
的地址属性(property)和MKPlacemark
类不允许您设置 title
你自己。
您可以做的是创建一个 MKPointAnnotation
(具有可设置的 title
属性)并设置其 title
任何你想要的,比如mapItem.name
.
例如:
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.title = mapItem.name;
pa.coordinate = mapItem.placemark.coordinate;
[self.mapView addAnnotation:pa];
注意:
您不必使用MKPointAnnotation
类(这只是最方便的)。
您还可以使用符合 MKAnnotation
的自定义类并且有一个可设置的 title
属性(或某个返回 MKMapItem
的 name
作为其 title
的类)。
另请注意,如果您希望能够访问相关的 MKMapItem
或MKPlacemark
在事后添加的注释中(例如在 map View 委托(delegate)方法中),您需要使用自定义类而不是 MKPointAnnotation
您可以在其中添加“sourceMapItem”或“sourcePlacemark”属性,您可以在创建注释时设置这些属性。
这样,您可以设置 title
根据需要但仍可访问所有原始 MKMapItem
或MKPlacemark
创建注释对象的值(如果仅使用 MKPointAnnotation
,则无法轻松完成此操作,因为它不保留对源 map 项或地标的引用)。
关于ios - MKMapItem 未在 MKPlacemark 上显示正确的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25532687/