Reputation: 127
I'm successfully displaying a map of the given location. I want to add an annotation to the map, without revealing the exact address (like the classic "pin" annotation points to).
I want to replicate the map effect that AirBnb has, but on the iPhone. If you check out any listing (https://www.airbnb.com/rooms/2289772) and look at the map view, to protect the privacy of the person renting the house or for whatever other reason, it doesn't show the exact address but rather a near-immediate approximation of the location.
- (void)viewDidLoad
{ self.itemDisplayMap.delegate = self;
CLLocationCoordinate2D cord = CLLocationCoordinate2DMake(lat, lng);
// I have a placemark and mapItem, but I'm not sure what to do with them
MKPlacemark *placemark = [[MKPlacemark alloc]initWithCoordinate:cord addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:placemark];
MKCoordinateRegion startRegion = MKCoordinateRegionMakeWithDistance(cord, 1500, 1500);
[self.itemDisplayMap setRegion:startRegion animated:YES];
}
Upvotes: 0
Views: 171
Reputation: 3993
It sounds like you want an MKOverlay which will let you draw something that scales with the map. Apple has some useful implementations of MKOverlay which should be a good starting point for you.
I'd start with MKCircle, which you give a center coordinate and radius. I'd also recommend adding a bit of random jitter to the (lat, long) pair so the exact address isn't at the center of the circle, but instead, contained inside of it.
Then to actually draw the circle, you'll need to initialize an MKCircleRenderer with that MKCircle.
Finally, in your MKMapViewDelegate, respond to -mapView:rendererForOverlay:
with the MKCircleRenderer.
Upvotes: 1