Shailesh
Shailesh

Reputation: 3118

How to add an UIImageView on the user current location on MKMapView

What I want to do is, I want to insert images on users current location (A thumbnail view of images), I have users current location and I have managed to insert an UIImageView on the MKMapView and also able to display the image on it as well.

But the thing I am unable to find/do is put the image on user's current location.

How can we add that UIImageView on user current location on MKMapView so that the image would appear on the user's current location.

Any ideas... ?

Thanks for your time..! :)

Upvotes: 0

Views: 1262

Answers (3)

AppleDelegate
AppleDelegate

Reputation: 4249

Initially define UIImage *selectedImage in your .h file. (Use UIImagePickerController for that.) Apply its delegate method to get the selected image from your camera roll:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

And then assign the same UIImage instead of "your user image" in the viewForAnnotation method, i.e.

userannotationView.image = selectedImage;

Upvotes: 0

user1082071
user1082071

Reputation:

You can make use of Core Location framework to determine the user's current location. You will get the user's current location as latitude and longitude (a coordinate). Once you have this, you can add an annotation (an instance of MKAnnotationView) on the map view at the coordinate.

To know how to determine user's location - Getting user's current location

To add annotations on Map - Annotating Maps

EDIT:

Custom image for annotation views - IOS: Adding image to custom MKAnnotationview

Upvotes: 2

AppleDelegate
AppleDelegate

Reputation: 4249

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation {

    if ([annotation isKindOfClass:[MKUserLocation class]]) {

 MKAnnotationView  *userannotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
            userannotationView.image = [UIImage imageNamed:@"your user image.png"];
            userannotationView.draggable = YES;
            userannotationView.canShowCallout = YES;


         return userannotationView;
    }else {
// your code to return annotationView or pinAnnotationView
}

Upvotes: 1

Related Questions