How to move a MKAnnotation without adding/removing it from the map?

In Swift 4.0 and IOS 11.0, I just add dynamic attribute to the coordinate property of child class of MKAnnotation class and it works: All Annotations on MapView update their location if coordinate value of MKAnnotation objects are updated: class CarAnnotation: NSObject, MKAnnotation { @objc dynamic var coordinate: CLLocationCoordinate2D //Add your custom code here }

UIPanGestureRecognizer on MKMapView?

Ok, because no one knew, I had to spent one Apple technical support consult for it. ;o) Because MKMapView evidently has its own recognizers to interact with user, you have to adhere to the UIGestureRecognizerDelegate protocol and implement (BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: like this: – (void)viewDidLoad { … UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(showPan)]; panGesture.delegate = self; … 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

iOS – MKMapView place annotation by using address instead of lat / long

Based on psoft‘s excellent information, I was able to achieve what I was looking for with this code. NSString *location = @”some address, state, and zip”; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder geocodeAddressString:location completionHandler:^(NSArray* placemarks, NSError* error){ if (placemarks && placemarks.count > 0) { CLPlacemark *topResult = [placemarks objectAtIndex:0]; MKPlacemark *placemark = [[MKPlacemark alloc] … Read more

How do I remove all annotations from MKMapView except the user location annotation?

Update: When I tried with the iOS 9 SDK the user annotation is no longer removed. You can simply use mapView.removeAnnotations(mapView.annotations) Historical answer (for apps that run on iOS before iOS 9): Try this: NSMutableArray * annotationsToRemove = [ mapView.annotations mutableCopy ] ; [ annotationsToRemove removeObject:mapView.userLocation ] ; [ mapView removeAnnotations:annotationsToRemove ] ; EDIT: Swift … Read more

Snapshot of MKMapView in iOS7

You can use MKMapSnapshotter and grab the image from the resulting MKMapSnapshot. See the discussion of it WWDC 2013 session video, Putting Map Kit in Perspective. For example: MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init]; options.region = self.mapView.region; options.scale = [UIScreen mainScreen].scale; options.size = self.mapView.frame.size; MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options]; [snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) … Read more

Convert MKCoordinateRegion to MKMapRect

To add another implementation to the pile: – (MKMapRect)MKMapRectForCoordinateRegion:(MKCoordinateRegion)region { MKMapPoint a = MKMapPointForCoordinate(CLLocationCoordinate2DMake( region.center.latitude + region.span.latitudeDelta / 2, region.center.longitude – region.span.longitudeDelta / 2)); MKMapPoint b = MKMapPointForCoordinate(CLLocationCoordinate2DMake( region.center.latitude – region.span.latitudeDelta / 2, region.center.longitude + region.span.longitudeDelta / 2)); return MKMapRectMake(MIN(a.x,b.x), MIN(a.y,b.y), ABS(a.x-b.x), ABS(a.y-b.y)); } NB: There are many ways to convert between MKMapRect and MKCoordinateRegion. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)