2

我得到了 a 的结果,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;
}

现在,当我将它添加到我的地图时......

id <MKAnnotation> annotation = mapItem.placemark;

[self.mapView addAnnotation:annotation];

它添加了一个图钉,当我点击它时会显示“Marton Road”,但我希望它显示“Cineworld”。

我发现很难找到任何有关将东西从其中取出MKMapItem并放入其中的信息MKPlacemark

如果我尝试mapItem.name在地标中使用,那么它们都会显示“美国”。

知道如何从中获得更多有用的信息吗?

4

1 回答 1

2

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属性的自定义类(或某些将MKMapItem'sname作为其返回的类title)。

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

这样,您可以title根据需要设置,但仍然可以访问创建注释对象的所有原始值MKMapItemMKPlacemark值(如果您使用它,您将无法轻松做到这一点,MKPointAnnotation因为它不保留对源地图项的引用或地标)。

于 2014-08-28T11:07:30.870 回答