iOS Mkmapview Custom Images Display on Top Left Corner

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



Leave a reply



Submit