gpt4 book ai didi

ios - MKMapItem 没有在 MKPlacemark 上显示正确的信息

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:09 25 4
gpt4 key购买 nike

我得到了 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 属性的地址,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 属性的自定义类(或某些返回 MKMapItemname 作为它的 title)。

另请注意,如果您希望能够在事后添加的注释中访问相关的 MKMapItemMKPlacemark(例如,在 map View 中委托(delegate)方法),您需要使用自定义类而不是 MKPointAnnotation,在其中添加可以在创建注释时设置的“sourceMapItem”或“sourcePlacemark”属性。

这样,您可以根据需要设置 title,但仍然可以访问注释对象所在的所有原始 MKMapItemMKPlacemark 值创建(如果仅使用 MKPointAnnotation,则无法轻松完成此操作,因为它不保留对源 map 项或地标的引用)。

关于ios - MKMapItem 没有在 MKPlacemark 上显示正确的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25532687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com