0

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..! :)

Shailesh
  • 3,072
  • 3
  • 24
  • 33

3 Answers3

2

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

Community
  • 1
  • 1
  • So instead of using UIImage view, I should use annotation for the purpose..! But is it possible to assign image from camera roll to annotation view .. ? – Shailesh Sep 25 '12 at 09:52
  • We can specify custom images to annotation views. Take a look at [MKAnnotationView](http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html#//apple_ref/doc/uid/TP40009497-CH6-SW1) class reference. It has a `image` property. You can set that image to your custom image and use it in the `- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(ActivityAnnotation *)annotation` delegate method. I have included a post in the edit section of my answer. –  Sep 25 '12 at 10:04
1
- (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
}
AppleDelegate
  • 4,269
  • 1
  • 20
  • 27
0

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;
AppleDelegate
  • 4,269
  • 1
  • 20
  • 27