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 MKPlacemark
returns the address for its title
property and the MKPlacemark
class doesn't let you set the title
yourself.
What you can do is create an MKPointAnnotation
(which has a settable title
property) and set its title
to whatever you want like mapItem.name
.
For example:
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.title = mapItem.name;
pa.coordinate = mapItem.placemark.coordinate;
[self.mapView addAnnotation:pa];
Note:
You don't have to use the MKPointAnnotation
class (it's just the most convenient available).
You can also use a custom class that conforms to MKAnnotation
and that has a settable title
property (or some class that returns the MKMapItem
's name
as its title
).
Also note that if you want to be able to access the related MKMapItem
or MKPlacemark
in the annotation you add after-the-fact (eg. in the map view delegate methods), you'll need to use a custom class instead of MKPointAnnotation
where you add a "sourceMapItem" or "sourcePlacemark" property that you can set when creating the annotation.
This way, you can set the title
as needed but still access all the original MKMapItem
or MKPlacemark
values from which the annotation object was created (you couldn't do this easily if you use just MKPointAnnotation
since it doesn't keep a reference to the source map item or placemark).