I get the results of a MKLocalSearch and it includes something like...
{
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;
}
Now when I add it to my map with...
id <MKAnnotation> annotation = mapItem.placemark;
[self.mapView addAnnotation:annotation];
It adds a pin that, when I tap on it shows "Marton Road" but I'd like it to show "Cineworld".
I'm finding it really hard to find any info on getting stuff out of the MKMapItem and into the MKPlacemark though.
If I try to use mapItem.name in the place mark then they all show "United States".
Any idea how I can get some more useful information out of this?
The
MKPlacemarkreturns the address for itstitleproperty and theMKPlacemarkclass doesn't let you set thetitleyourself.What you can do is create an
MKPointAnnotation(which has a settabletitleproperty) and set itstitleto whatever you want likemapItem.name.For example:
Note:
You don't have to use the
MKPointAnnotationclass (it's just the most convenient available).You can also use a custom class that conforms to
MKAnnotationand that has a settabletitleproperty (or some class that returns theMKMapItem'snameas itstitle).Also note that if you want to be able to access the related
MKMapItemorMKPlacemarkin the annotation you add after-the-fact (eg. in the map view delegate methods), you'll need to use a custom class instead ofMKPointAnnotationwhere you add a "sourceMapItem" or "sourcePlacemark" property that you can set when creating the annotation.This way, you can set the
titleas needed but still access all the originalMKMapItemorMKPlacemarkvalues from which the annotation object was created (you couldn't do this easily if you use justMKPointAnnotationsince it doesn't keep a reference to the source map item or placemark).