CLLocation Category for Calculating Bearing w/ Haversine function

Your code seems fine to me. Nothing wrong with the calculous. You don’t specify how far off your results are, but you might try tweaking your radian/degrees converters to this: double DegreesToRadians(double degrees) {return degrees * M_PI / 180.0;}; double RadiansToDegrees(double radians) {return radians * 180.0/M_PI;}; If you are getting negative bearings, add 2*M_PI to … Read more

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

Programmatically open Maps app in iOS 6

Here’s the official Apple way: // Check for iOS 6 Class mapItemClass = [MKMapItem class]; if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { // Create an MKMapItem to pass to the Maps app CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(16.775, -3.009); MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]; MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark]; [mapItem setName:@”My Place”]; // Pass the … Read more

How to add a button to the MKPointAnnotation?

You are doing it right.You just need to have these methods implemented for adding button along with title and subtitle iOS 8 and Xcode 6 import UIKit import MapKit import CoreLocation class MapKitViewController: UIViewController, MKMapViewDelegate { let locationManager = CLLocationManager() @IBOutlet weak var nmapView: MKMapView! override func viewDidLoad() { super.viewDidLoad() locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() let location = … Read more

Getting the bounds of an MKMapView

Okay I officially answered my own question but since I didn’t find it anywhere before I’ll post the answer here: //To calculate the search bounds… //First we need to calculate the corners of the map so we get the points CGPoint nePoint = CGPointMake(self.mapView.bounds.origin.x + mapView.bounds.size.width, mapView.bounds.origin.y); CGPoint swPoint = CGPointMake((self.mapView.bounds.origin.x), (mapView.bounds.origin.y + mapView.bounds.size.height)); //Then … Read more

MKPinAnnotationView: Are there more than three colors available?

some more 😉 And the original ones : And the code: – (MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView* anView =[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@”test”]; anView.pinColor=MKPinAnnotationColorPurple; UIImage* image = nil; // 2.0 is for retina. Use 3.0 for iPhone6+, 1.0 for “classic” res. UIGraphicsBeginImageContextWithOptions(anView.frame.size, NO, 2.0); [anView.layer renderInContext: UIGraphicsGetCurrentContext()]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData* imgData = UIImagePNGRepresentation(image); NSString* … Read more