Chintan Patel
Chintan Patel

Reputation: 3165

Image instead of a the default pin in iPhone's MapKit framework?

Is it possible to have our own image instead of the default pin in MapKit map on iPhone?

I am working on an application which would show friends' locations much like Google Latitude and need to show image of friends at their locations.

It is possible using the JavaScript Google Map but i want to know if someone can give some sample code for MapKit based map.

Upvotes: 6

Views: 7702

Answers (3)

sundeep
sundeep

Reputation: 43

By using span property you can easily zoom to your require

MKCoordinateSpan span;

MKCoordinateRegion region;


mapView.scrollEnabled=YES;
span.latitudeDelta = 100.0;//more value you set your zoom level will increase
span.longitudeDelta =100.0;//more value you set your zoom level will increase
mapView.showsUserLocation=YES;
region.span = span;


region.center = from.coordinate;
  [mapView setRegion:region animated:YES];
 [mapView regionThatFits:region];
[mapView addAnnotation:from];

Upvotes: 0

Dishant
Dishant

Reputation: 917

You can also set the frame of the image. For that in above code we have to make this simple changes.

UIImage *pinImage = [UIImage imageNamed:@"image.png"];

UIImageView *imageView = [[[UIImageView alloc] initWithImage:pinImage] autorelease];

       imageView.frame = CGRectMake(-20, 0, 40, 30);

[annotation addSubview:imageView];

And we have to comment the line

// annotation.image = [UIImage imageNamed:@"image.png"];

Upvotes: 2

Jay Vachhani
Jay Vachhani

Reputation: 696

Yes it is possible. For that u have to use MKAnnotationView instead of MKPinAnnotationView. and do not use annotation.animatesDrop property.

Here are the sample code you can use in viewForAnnotation,

    annotation = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"try"];
    annotation.canShowCallout = YES;

    annotation.image = [UIImage imageNamed:@"image.png"];


    return annotation;

Upvotes: 14

Related Questions