मैप में पिन के बजाय छवियों को कैसे दिखाऊं। अब तक मैं केवल टैप पर पिन जोड़ सकता हूं। .m का एक नमूना कोड अत्यंत मदद करेगा क्योंकि मैं अभी भी आईओएस प्रोग्रामिंग के लिए नया हूं।आईओएस मैपकिट कस्टम पिन
उत्तर
#pragma mark -
#pragma mark MKMapView delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:@"someImage.png"];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
return nil;
}
संपादित करें:
मैं MKAnnotationView
के बारे में आप सभी को समझा सकता है, लेकिन मुझे लगता है कि आप एप्पल द्वारा प्रदान की किसी अन्य स्रोत से की तुलना में कहीं बेहतर स्पष्टीकरण होने के लिए प्रलेखन मिल जाएगा। लिंक में अवलोकन अनुभाग देखें।
https://developer.apple.com/documentation/mapkit/mkannotationview
यह काम करता है। धन्यवाद। क्या आप कृपया पारित पैरामीटर और एनोटेशन पहचानकर्ता के बारे में एक संक्षिप्त विवरण शामिल कर सकते हैं? क्या यह .NET की टैग प्रॉपर्टी के समान है? – Bahamut
मेरी आवश्यकता में, "someImage.png" का उपयोग करने के बजाय, मुझे UIView पर आकर्षित करना होगा और [annotationView addSubView: myView] का उपयोग करना होगा। यह ठीक काम कर रहा है। लेकिन इसके टैप पर "didSelectAnotationView" को कॉल नहीं किया जा रहा है। कुछ ग़लत है? – Satyam
क्या आपको उस दृश्य के उपयोगकर्ता इंटरैक्शन को अक्षम करने की आवश्यकता हो सकती है। – Robin
जाओ Xcode के आयोजक के लिए और फिर दस्तावेज़ पर जाएं और खोज weatherMap यह टिप्पणी पर छवियों सहित के साथ नक्शे के लिए उदाहरण दिखाता है।
#pragma mark -
#pragma mark MKMapView delegate
-(void)addAllPinsOnMapView
{
MKCoordinateRegion region = mapViewOffer.region;
region.center = CLLocationCoordinate2DMake(12.9752297537231, 80.2313079833984);
region.span.longitudeDelta= 0.1f;
region.span.latitudeDelta= 0.1f;
[mapViewOffer setRegion:region animated:YES];
mapViewOffer.delegate=self;
arrMapPin=[[NSMutableArray alloc] init];
NSArray *name=[[NSArray alloc]initWithObjects:
@"Title1",
@"Title2",
@"Title3", nil];
NSMutableArray *arrCoordinateStr = [[NSMutableArray alloc] initWithCapacity:name.count];
[arrCoordinateStr addObject:@"12.970760345459,80.2190093994141"];
[arrCoordinateStr addObject:@"12.9752297537231,80.2313079833984"];
[arrCoordinateStr addObject:@"12.9788103103638,80.2412414550781"];
for(int i = 0; i < name.count; i++)
{
NSArray *components = [[arrCoordinateStr objectAtIndex:i] componentsSeparatedByString:@","];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
mapPin.title = [name objectAtIndex:i];
mapPin.coordinate = coordinate;
[mapViewOffer addAnnotation:mapPin];
}
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:
(MKAnnotationView *)view
{
NSLog(@"%@",view.annotation.title);
NSLog(@"%f",view.annotation.coordinate.latitude);
NSLog(@"%f",view.annotation.coordinate.longitude);
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTapped:)];
[view addGestureRecognizer:tapGesture];
}
-(void)calloutTapped:(UITapGestureRecognizer *) sender
{
NSLog(@"Callout was tapped");
MKAnnotationView *view = (MKAnnotationView*)sender.view;
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
//[self performSegueWithIdentifier:@"annotationDetailSegue" sender:annotation];
OfferDetailsViewController *objOfferDetailsViewController = [[OfferDetailsViewController alloc]init];
[self.navigationController pushViewController:objOfferDetailsViewController animated:YES];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)theMapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = @"annotationViewID";
pinView = (MKAnnotationView *)[mapViewOffer dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
}
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"placeholder"];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
return pinView;
}
एक लंबा कोड स्निपेट पोस्ट करने से पहले कुछ विवरण जोड़ें। –
- 1. आईओएस मैपकिट कस्टम कॉलआउट
- 2. मैं आईफोन मैपकिट में कस्टम पिन कैसे जोड़ूं?
- 3. मैपकिट आईओएस
- 4. मैपकिट पॉलीलाइन कस्टम ज़ूम?
- 5. मैपकिट
- 6. मैपकिट
- 7. आईफोन के मैपकिट ढांचे में डिफ़ॉल्ट पिन की बजाय छवि?
- 8. आईओएस: दो एनोटेशन पॉइंट के लिए मैपकिट में ज़ूम करें
- 9. कस्टम पिन एनीमेशन - एमकेमैप व्यू
- 10. आईओएस
- 11. टबल्सशूटिंग मैपकिट प्रदर्शन
- 12. मैपकिट
- 13. मैपकिट
- 14. मैपकिट
- 15. मैपकिट
- 16. मैपकिट -
- 17. मैपकिट फ्रेमवर्क के साथ कस्टम आइकन का उपयोग कैसे करें?
- 18. कस्टम एनोटेशन पिन परिवर्तन लंबे नल
- 19. कस्टम एंड्रॉइड पिन कोड एंट्री विजेट
- 20. आईओएस: कस्टम एमकेएनोटेशनव्यू
- 21. पिन
- 22. आईओएस 5 मैपकिट ओवरले के साथ क्रैश जब ज़ूम/पैन
- 23. मानचित्र को टैप करके आईओएस मैपकिट एनोटेशन कॉलआउट बंद करना
- 24. आईओएस में मैपकिट 6 - आसपास के स्थान कैसे खोजें ...?
- 25. (आईफोन) ओएस 4.0 मैपकिट का उपयोग कर ड्रैगगेबल पिन को कैसे कार्यान्वित करें?
- 26. आईपैड मैपकिट - "वर्तमान स्थान" का शीर्षक बदलें
- 27. MKMapView वर्तमान पिन कस्टम पिन के रूप में दिखा रहा है
- 28. आईओएस 5 कस्टम फ़ॉन्ट्स
- 29. आईओएस कस्टम निष्क्रिय टाइमर
- 30. आईओएस: कस्टम संकल्प
एक छोटी सी खोज एक लंबा रास्ता चला जाता है :) http://stackoverflow.com/questions/4579397/iphone-mapkit-adding-custom-image-and-pins-to-annotations और भी है: http://stackoverflow.com/questions/7124028/change-pin- डिज़ाइन –