Showing custom Annotation View on MKMapView
you need to set your Class as MKMapViewDelegate
and fill this method:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
CustomMapAnnotationView *annotationView = nil;
pinView.image = [UIImage imageNamed:@"annotationImage"];
[pinView.layer setCornerRadius:8.0];
[pinView setClipsToBounds:YES];
NSString* identifier = @"CustomMapAnnotation";
CustomMapAnnotationView *newAnnotationView = (CustomMapAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if(nil == newAnnotationView) {
newAnnotationView = [[[CustomMapAnnotationView alloc] initWithAnnotation: pinView reuseIdentifier:identifier] autorelease];
}
annotationView = newAnnotationView;
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}
Thus, you can return a custom Class, subclass of MKAnnotationView
, and you can add badge now to your custom view.
How do I add a UIView on top of a MKAnnotationView and then display it on a MKMapView?
You left out a tiny but key step: in every case, you must assign the incoming annotation to the annotation view's annotation
property.
How to show the user location icon on top of the pin image?
You can fetch the annotation for the userLocation and bring his view to front.
MKAnnotationView *annotationView = [self.mapView viewForAnnotation:self.mapView.userLocation];
[annotationView.superView bringSubviewToFront:annotationView];
GoogleMaps camera target in top left corner of map iOS since pod update
I found I was able to solve this problem by adding the map creation to ViewWillAppear as opposed to having it in the ViewDidLoad.
override func viewWillAppear(_ animated: Bool) {
let ud = UserDefaults.standard
let startingX = ud.double(forKey: "startingX")
let startingY = ud.double(forKey: "startingY")
let camera = GMSCameraPosition.camera(withLatitude: startingX, longitude: startingY, zoom: 18.0)
googleMapView.camera = camera
self.googleMapView.mapType = .hybrid
self.googleMapView.settings.scrollGestures = true
self.googleMapView.settings.rotateGestures = true
self.googleMapView.settings.consumesGesturesInView = true
}
Related Topics
How to Catch Nsunknownkeyexception in Swift 2.2
Uialertcontroller Title and Message Not Appearing
Change Uitabbar Tint Colors in the More Menu
Load Offline Cached JSON Using Afnetworking
Binary Operator + Cannot Be Applied to Operands of Type Cgfloat Int
Which View Controller Should I Pass in My Swift Native Code for a Flutter Plugin
Circular Button Becomes Rounded Rectangle After Size Increase
How to Change Uitextfield Color in Searchcontroller
Match the Data Type of a Object in Swift
Disable Long Press Back Button (Callout Menu)
Uiimageview .Scaleaspectfit and Autolayout Not Working Programmatically from Swift
How to Send Request from iOS (Swift) to Dialogflow V2 API Without Cloud Functions
Xcode 9.3 - Nspredicate Bool Crash