0

I am trying to create many pins from a database of locations, each with custom images. The images are passed from the server in base64 format, I am able to create a UIImage from the base64 data, but I cannot upload the image as the icon instead of the pin for each annotation.

Any ideas how I can do this?

I tried to follow these SO posts to help, but they can only create a preset one, I can't figure out how edit all of them so they each have a unique icon:

SO link 1 and SO link 2

Any ideas?

here is my code to create the pins/annotations incase anyone is interested:

func mapTheseCoordinates(lat: Double, lng: Double, username: NSString, fullname: NSString) {
    let location = CLLocationCoordinate2D(
        latitude: lat,
        longitude: lng
    )
    // 2
    let span = MKCoordinateSpanMake(0.15, 0.15)
    let region = MKCoordinateRegion(center: location, span: span)
    mapView.setRegion(region, animated: true)

    //3
    let annotation = MKPointAnnotation()
    annotation.setCoordinate(location)
    annotation.title = username
    annotation.subtitle = fullname
    mapView.addAnnotation(annotation)
}
Community
  • 1
  • 1
Haring10
  • 1,517
  • 1
  • 19
  • 37

1 Answers1

0

You can use this Delegate event of mkmapview, here you can change different images as per your annotation

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
    //MyPin.pinColor = MKPinAnnotationColorPurple;
    MyPin.highlighted = NO;
    MyPin.image = [UIImage imageNamed:@"pin_red"];

    return MyPin;
}

this delegate event will be called everytime you add anotation, but dont forget to set delegate for mapview

[mapLocation addAnnotation:annotObj]; 
Parth Pandya
  • 1,460
  • 3
  • 18
  • 34
  • How can I do this in swift? I did tag the post as swift, and provided swift code, I don't know Objective C well. – Haring10 Oct 17 '14 at 11:32
  • I don't know swift but I guess it should work http://stackoverflow.com/questions/25631410/swift-different-images-for-annotation – Parth Pandya Oct 17 '14 at 11:40