Positioning MKMapView to show multiple annotations at once

The link posted by Jim is now dead, but i was able to find the code (which I had bookmarked somewhere). Hope this helps. – (void)zoomToFitMapAnnotations:(MKMapView *)mapView { if ([mapView.annotations count] == 0) return; CLLocationCoordinate2D topLeftCoord; topLeftCoord.latitude = -90; topLeftCoord.longitude = 180; CLLocationCoordinate2D bottomRightCoord; bottomRightCoord.latitude = 90; bottomRightCoord.longitude = -180; for(id<MKAnnotation> annotation in mapView.annotations) { … 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.

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

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

How to pass prepareForSegue: an object

Simply grab a reference to the target view controller in prepareForSegue: method and pass any objects you need to there. Here’s an example… – (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Make sure your segue name in storyboard is the same as this line if ([[segue identifier] isEqualToString:@”YOUR_SEGUE_NAME_HERE”]) { // Get reference to the destination view controller … Read more