MKAnnotationView – Lock custom annotation view to pin on location updates

I created a project based on your CalloutMapAnnotationView demonstrating a IB based solution. Arrow keys animate motion of the location annotation and it’s callout annotation. The callout now also automatically resizes based on the supplied contentView, and the view is loaded from a separate nib. Good luck! https://github.com/jacobjennings/JJMapCallout

Detecting a point in a MKPolygon broke with iOS7 (CGPathContainsPoint)

For some reason (possibly a bug), the path property returns NULL in the current release of iOS 7. A workaround is to construct your own CGPathRef from the points of the polygon. With this method, you don’t need a reference to the MKPolygonView or the MKPolygonRenderer. For example: CGMutablePathRef mpr = CGPathCreateMutable(); MKMapPoint *polygonPoints = … Read more

iPhone: How to draw line between two points on MapKit?

First make your view controller implement the MKMapViewDelegate protocol and declare the properties you will need: @property (nonatomic, retain) MKMapView *mapView; //this is your map view @property (nonatomic, retain) MKPolyline *routeLine; //your line @property (nonatomic, retain) MKPolylineView *routeLineView; //overlay view then in viewDidLoad (for example, or wherever you initialize) //initialize your map view and add … Read more

How to customize the callout bubble for MKAnnotationView?

There is an even easier solution. Create a custom UIView (for your callout). Then create a subclass of MKAnnotationView and override setSelected as follows: – (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if(selected) { //Add your custom view to self… } else { //Remove your custom view… } } Boom, job done.

Calculate new coordinate x meters and y degree away from one coordinate

Unfortunately, there’s no such function provided in the API, so you’ll have to write your own. This site gives several calculations involving latitude/longitude and sample JavaScript code. Specifically, the section titled “Destination point given distance and bearing from start point” shows how to calculate what you’re asking. The JavaScript code is at the bottom of … Read more

Drawing a route in MapKit in iOS

The following viewDidLoad will (1) set two locations, (2) remove all the previous annotations, and (3) call user defined helper functions (to get route points and draw the route). -(void)viewDidLoad { [super viewDidLoad]; // Origin Location. CLLocationCoordinate2D loc1; loc1.latitude = 29.0167; loc1.longitude = 77.3833; Annotation *origin = [[Annotation alloc] initWithTitle:@”loc1″ subTitle:@”Home1″ andCoordinate:loc1]; [objMapView addAnnotation:origin]; // … Read more

UIImage(contentsOfFile:) returning nil despite file existing in caches directory [duplicate]

The problem there is that you are using URL property absoluteString where you should be using the path property. The difference between absoluteString and path properties is that absoluteString includes the file url scheme (“file://”) which is the reason it doesn’t find the file at what was supposed to be its path but it is … Read more