/ / IPhone में MKMapView में UIImage कैसे जोड़ें? - iphone, ios, ipad, mkmapview

आईफोन में MKMapView में UIImage कैसे जोड़ें? - आईफोन, आईओएस, आईपैड, mkmapview

मैं MKMapview में एक UIImage जोड़ना चाहता हूं।

i.e .: एक विशेष स्थान, मैं "apple.jpg" नामक एक छवि जोड़ना चाहता हूं।

मैं नहीं जानता कि यह कैसे करना है।

जैसा कि मैंने पहले ही एक एनोटेशन के रूप में एक ड्रैग करने योग्य पिन जोड़ा है। लेकिन मैं नहीं जानता कि क्या मैं कई छवियां जोड़ सकता हूं या नहीं।

उत्तर:

जवाब के लिए 5 № 1

MKMapView के एक भाग के रूप में छवि जोड़ने के लिए यह ट्यूटोरियल देखें ...

i.ndigo mkmapview

और MapView पर एक पिन के रूप में छवि जोड़ने के लिए तो इस कोड का उपयोग करें ...

MKAnnotationView *annotationView = [[[MKAnnotationView alloc] init];

annotationView.image = [UIImage imageNamed:@"apple.png"];
annotationView.annotation = annotation;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annotationView.rightCalloutAccessoryView.tag = 101;

annotationView.canShowCallout = YES;
[yourMapView addAnnotation:annotationView];

जवाब के लिए 2 № 2

जैसा कि @ कसेम बघेर उल्लेख करते हैं, आपको कस्टम बनाने की आवश्यकता है MKAnnotationView जो भी ट्यूटोरियल देखें (उदाहरण)


उत्तर № 3 के लिए 1

आपकी छवि png प्रारूप में होनी चाहिए नीचे दिए गए कोड को देखें।

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

MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
if (!pinView) {
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] autorelease];
pinView.image = [UIImage imageNamed:@"apple.png"];
pinView.canShowCallout = YES;
}
}

उत्तर के लिए 1 № 4

यह वर्किंग कोड है और मैंने पहले से ही नीचे कोड के साथ किया है कोई आवश्यक छवि नहीं है। png, .jpg या .gif इसके किसी भी फॉर्मेट का उपयोग कर सकते हैं

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;
NSString *defaultPinID = @"myPin";
pinAnnotation = (MKPinAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinAnnotation == nil )
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

pinAnnotation.image = [UIImage imageNamed:@"marker_postoffice.png"];
pinAnnotation.annotation = annotation;
pinAnnotation.canShowCallout = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];



[infoButton addTarget:self action:@selector(showDetails)forControlEvents:UIControlEventTouchUpInside];
pinAnnotation.rightCalloutAccessoryView = infoButton;





// now you can set diff image by  [annotation title] you  can set diff image with if else condition like below code


if([[annotation title] isEqualToString:objAppDelegate.OfficePinTitle])
{

pinAnnotation.image = [UIImage imageNamed:@"marker_postoffice.png"];
pinAnnotation.annotation = annotation;
pinAnnotation.canShowCallout = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

infoButton addTarget:self
action:@selector(showDetails)forControlEvents:UIControlEventTouchUpInside];

pinAnnotation.rightCalloutAccessoryView = infoButton;

}
else
{

pinAnnotation.image = [UIImage imageNamed:@"marker_red_postoffice.png"];
pinAnnotation.canShowCallout = YES;
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

[infoButton addTarget:self action:@selector(showDetails)forControlEvents:UIControlEventTouchUpInside];

pinAnnotation.rightCalloutAccessoryView = infoButton;
}


}