Why does a custom MKMapView annotation image disappear on touch? - iphone

I am annotating my map and setting an image just fine, but when I tap the annotation on the MapView, the image goes from my custom image back to the red pin. Why is this?
- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
MKPinAnnotationView *annotation = [[MKPinAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:#"currentloc"];
if (annotation == nil) {
annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:#"currentloc"];
}
annotation.image = [UIImage imageNamed:#"anno.png"];
annotation.canShowCallout = YES;
annotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bus_stop_30x30.png"]];
annotation.leftCalloutAccessoryView = imgView;
return annotation;
}
My code looks identical to some sample code that does not produce this problem.

Answering my own question here, just in case others have the same issue. Notice that I am using "MKPinAnnotationView" - it should be changed to "MKAnnotationView" and everything works.
Fixed code:
- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
MKAnnotationView *annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:#"currentloc"];
if (annotation == nil) {
annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:#"currentloc"];
}
annotation.image = [UIImage imageNamed:#"anno.png"];
annotation.canShowCallout = YES;
annotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bus_stop_30x30.png"]];
annotation.leftCalloutAccessoryView = imgView;
return annotation;
}

I think this is one of the best ways:
(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
NSLog(#"welcome into the map view annotation");
MyAnnotation* myAnnotation1=annotation;
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if([mapView isEqual:mapMainView]== NO)
{
return nil;
}
// try to dequeue an existing pin view first
// if ([annotation isKindOfClass:[myAnnotation1 class]])
// {
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (nil == pinView)
{
MKAnnotationView* annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier] autorelease];
// annotationView.canShowCallout = YES;
// pinView.animatesDrop=YES;
//pinView.pinColor=MKPinAnnotationColorPurple;
//image
UIImage* flagImage = [UIImage imageNamed:#"map_marker_over2.png"];
CGRect resizeRect;
resizeRect.size = flagImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[MapPropertyViewController annotationPadding],
[MapPropertyViewController annotationPadding]).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [MapPropertyViewController calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[flagImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
rightButton.tag = myAnnotation1.tagAnnotation;
annotationView.rightCalloutAccessoryView = rightButton;
profileIconView = [[UIImageView alloc]initWithFrame:CGRectMake(18.5f, 10.0f, 37.0f, 30.0f)];
annotationView.leftCalloutAccessoryView = profileIconView;
//image
img = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:[arrImages objectAtIndex:myAnnotation1.tagAnnotation]]]];
NSLog(#"Annotation Click %d",[arrImages count]);
NSLog(#"image %#",img);
profileIconView.image=img;
[profileIconView release];
[annotationView setEnabled:YES];
[annotationView setCanShowCallout:YES];
return annotationView;
}
return pinView;
// }
// return nil;
}

Try this if you want to set both Source to Destination pin images different.
MKPointAnnotation * sourceAnno= [[MKPointAnnotation alloc] init];
sourceAnno.coordinate=CLLocationCoordinate2DMake(YourSourcelatitude,YourSourcelongitude);
[sourceAnno setAccessibilityLabel:#“Source”];
sourceAnno.title = #“You”;
[mapview addAnnotation: sourceAnno];
DestinationAnno = [[MKPointAnnotation alloc] init];
DestinationAnno.coordinate = CLLocationCoordinate2DMake(YourDestinationlatitude,YourDestinationlongitude);
[DestinationAnno setAccessibilityLabel:#“Destination”];
DestinationAnno.title =#“Destination”;
[mapview addAnnotation: DestinationAnno];
In Delegate Method
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPointAnnotation *PointAnno=(MKPointAnnotation *)annotation;
NSString * kPinAnnotationIdentifier = PointAnno.accessibilityLabel;
MKAnnotationView *AnnotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:kPinAnnotationIdentifier];
if ([kPinAnnotationIdentifier isEqualToString:#"Source"])
{
AnnotationView.centerOffset = CGPointMake(8, -14);
AnnotationView.calloutOffset = CGPointMake(-8, 0);
AnnotationView.image = [UIImage imageNamed:#"pin_blue.png"];
AnnotationView.canShowCallout = YES;
}
else if([kPinAnnotationIdentifier isEqualToString:#"Destination"])
{
AnnotationView.centerOffset = CGPointMake(8, -14);
AnnotationView.calloutOffset = CGPointMake(-8, 0);
AnnotationView.image = [UIImage imageNamed:#"pin_red.png"];
AnnotationView.canShowCallout = YES;
}
return AnnotationView;
}
Thank you

Related

How to add UIImage in MKMapView in iPhone?

I want to add a UIImage in MKMapview.
i.e.: One a particular location, I want to add an image called "apple.jpg".
I don't know how to do that.
As I have already added a draggable pin as an annotation. But I don't know if I can add multiple images or not.
For add image as a Part of MKMapView see this Tutorial...
i.ndigo mkmapview
and for add Image as a Pin on MapView then use this bellow code...
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];
as #Kassem Bagher mentions, you need to create custom MKAnnotationView , check whatever tutorial (example)
Your image must be in png format see the code below.
- (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;
}
}
This is working code and i already done with below code no necessory image is .png , .jpg or .gif its any formate you can use it
- (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;
}
}

Adding multiline subtitle into MKAnotationView Xcode

I am having a problem with displaying a multiline MKAnnotaion in Xcode 4.2
here is my code that is displaying a single line subtitle for the annotation.
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString* MyAnnotationIdentifier = #"MyAnnotationIdentifier";
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:MyAnnotationIdentifier] autorelease];
//--- adding pin color and animation
customPinView.pinColor = MKPinAnnotationColorRed;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
return customPinView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
So how to add a multiline subtitle?
Thanks in advance.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"loc"];
// Button
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 23, 23);
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[button setImage:[UIImage imageNamed:yourImageName] forState:UIControlStateNormal];
[advertButton addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = button;
// Image and two labels
UIView *leftCAV = [[UIView alloc] initWithFrame:CGRectMake(0,0,23,23)];
[leftCAV addSubview : yourImageView];
[leftCAV addSubview : yourFirstLabel];
[leftCAV addSubview : yourSecondLabel];
annotationView.leftCalloutAccessoryView = leftCAV;
annotationView.canShowCallout = YES;
return pin;
}
also see this link for detail
How to display 2 lines of text for subtitle of MKAnnotation and change the image for the button on the right?
plz use this
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[CustomAnnotation class]]) {
CustomAnnotation *customAnnotation = (CustomAnnotation *) annotation;
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:#"CustomAnnotation"];
if (annotationView == nil)
annotationView = customAnnotation.annotationView;
else
annotationView.annotation = annotation;
//Adding multiline subtitle code
UILabel *subTitlelbl = [[UILabel alloc]init];
subTitlelbl.text = #"sri ganganagar this is my home twon.sri ganganagar this is my home twon.sri ganganagar this is my home twon. ";
annotationView.detailCalloutAccessoryView = subTitlelbl;
NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:subTitlelbl attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationLessThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:150];
NSLayoutConstraint *height = [NSLayoutConstraint constraintWithItem:subTitlelbl attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:0];
[subTitlelbl setNumberOfLines:0];
[subTitlelbl addConstraint:width];
[subTitlelbl addConstraint:height];
return annotationView;
} else
return nil;
}

Setting image for MKAnnotation

I added MKAnnotation in my mapview using the following code.
Flag *flag = [[Flag alloc] init];
flag.title = #"Golf Course";
flag.subtitle = #"Green";
flag.coordinate =CLLocationCoordinate2DMake(28.457394,77.108667);
[mapView addAnnotation:flag];
and am setting image like
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation
{
if(([annotation isKindOfClass:[Flag class]]))
{
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = #"PinId1";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:#"pin1"] autorelease];
//pinView= [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"pin1"];
pinView.canShowCallout = YES;
pinView.draggable = YES;
[pinView setImage:[UIImage imageNamed:#"flag2.png"]];
}
else
{
[mapView.userLocation setTitle:#"I am here"];
}
}
return pinView;
}
but am not getting the image for MKAnnoation.What is wrong am doing?Please help me.
I have the same issue. Now using the working version as given below.
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[Annotation class]])
{
static NSString* SFAnnotationIdentifier = #"SFAnnotationIdentifier";
MKPinAnnotationView* pinView =
(MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:SFAnnotationIdentifier];
if (!pinView)
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:SFAnnotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
UIImage *flagImage = [UIImage imageNamed:#"map_pin.png"];
CGRect resizeRect;
resizeRect.size = flagImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
10.5,
10.5).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + 40.0;
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[flagImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
Annotation *annoterObject = (Annotation *) annotation;
rightButton.tag = annoterObject.annoteCount;
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}
This is the working code.
Where you have to set image?is it on callouts? if yes replace [pinView setImage:[UIImage imageNamed:#"flag2.png"]]; with pinView.leftCalloutAccessoryView = [[ UIImageView alloc]initWithImage:[UIImage imageNamed:#"flag2.png"]];

iphone pinView.animatesdrop not working

Here is my code of - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation method. The method is getting called but the pinView.animatesDrop = YES and pinView.canShowCallout = YES is not working. Please help
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:#","];
NSLog(#"pin map");
if(pinView == nil)
{
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#""];
pinView.animatesDrop = YES;
pinView.canShowCallout = YES;
UIImage *image = [UIImage imageNamed:#"ann.png"];
CGRect resizeRect;
resizeRect.size = image.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[map annotationPadding],
[map annotationPadding]).size;*/
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [map calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[image drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
pinView.image = resizedImage;
pinView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
if (annotation == mapView.userLocation)
{
return nil;
}
return pinView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
please see this blog-
here
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
NSLog(#"welcome into the map view annotation");
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorPurple;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"profile.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
[profileIconView release];
return pinView;
}
I worked out what my problem was:
I had not set the delegate for the class.mapView.delegate=self;

Objective-C Class Reference: Symbols not found error

I've been working on this iPhone app for a while now, and I had it completely finished and working. The project I was expanding on was downloaded from a subversion repository online that my professor had given me access too. I accidentally didn't download the "root" copy or something like that, so I wasn't able to commit any changes to the repository. With my instructors help, I downloaded the root copy today and added all my class files to it so I could commit the changes. However, I am now getting 3 strange errors that I have never seen before:
Undefined symbols:
"_OBJC_CLASS_$_mapListViewController",
referenced from:
objc-class-ref-to-mapListViewController
in mapViewController.o
"_OBJC_CLASS_$_mapParser",
referenced from:
objc-class-ref-to-mapParser in mapViewController.o
"_OBJC_CLASS_$_mapTabViewController",
referenced from:
objc-class-ref-to-mapTabViewController
in mapViewController.o
ld: symbol(s) not found collect2: ld
returned 1 exit status
That is the exact error message I am getting. I have not changed any code from the version that was working completely earlier this morning. Any advice? The mapViewController file seems to be what is causing the issue, so here is that as well:
#import "mapViewController.h"
#import "locationDetailViewController.h"
#import "DPUAnnotation.h"
#import "mapParser.h"
#import "mapListViewController.h"
#import "mapTabViewController.h"
#implementation mapViewController
#synthesize locationManager, mapView, mapAnnotations, mParser, mapListView, tabView;
#class DPUAnnotation;
+ (CGFloat)annotationPadding;
{
return 10.0f;
}
+ (CGFloat)calloutHeight;
{
return 40.0f;
}
- (void)gotoLocation
{
// start off by default at DePauw campus
MKCoordinateRegion newRegion;
newRegion.center.latitude = 39.639348;
newRegion.center.longitude = -86.861231;
newRegion.span.latitudeDelta = 0.006776;
newRegion.span.longitudeDelta = 0.006291;
[self.mapView setRegion:newRegion animated:YES];
}
- (void)viewDidLoad {
self.title = #"Map";
mapView.mapType = MKMapTypeHybrid;
mapView.showsUserLocation = YES;
mapListView = [[mapListViewController alloc] initWithNibName:#"mapListView" bundle:nil];
tabView = [[mapTabViewController alloc] initWithNibName:#"mapTabViewController" bundle:nil];
if (mapAnnotations == nil)
{
self.mapAnnotations = [NSMutableArray array];
}
else
{
[mapAnnotations removeAllObjects];
}
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"btn_home.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(mainpageClicked)];
[self.navigationItem setLeftBarButtonItem:backButton];
UIBarButtonItem *mapListButton = [[UIBarButtonItem alloc] initWithTitle:#"Building List" style:UIBarButtonItemStylePlain target:self action:#selector(pushMapList)];
[self.navigationItem setRightBarButtonItem: mapListButton];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[self gotoLocation];
self.mParser = [[[mapParser alloc] init] autorelease];
self.mParser.delegate = self;
[self.mParser start];
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:(BOOL)animated];
}
- (void)dealloc
{
[mapView release];
[locationManager release];
[mapAnnotations release];
[super dealloc];
}
/*
* Returns the User to the main Application Page
*/
- (IBAction)mainpageClicked
{
NSLog(#"Return To Main page Clicked");
[self.parentViewController dismissModalViewControllerAnimated:YES];
[self.navigationController release];
}
- (IBAction) pushMapList
{
tabView = [[mapTabViewController alloc] initWithNibName:#"mapTabViewController" bundle:nil];
tabView.mapAnnotations2 = mapAnnotations;
[self.navigationController pushViewController:tabView animated:YES];
[tabView release];
}
- (IBAction)addAnnotation
{
[self.mapView removeAnnotations:self.mapView.annotations];
for (int i = 0; i < [mapAnnotations count]; i++)
[mapView addAnnotation:[mapAnnotations objectAtIndex:i]];
NSLog(#"BLAH BLAH BLAH PLEASE PRINT");
if([mapAnnotations count] == 0)
NSLog(#"array is empty");
}
- (void)showDetails:(id)sender
{
NSInteger selectedIndex = [sender tag];
DPUAnnotation *selectedObject = [mapAnnotations objectAtIndex:selectedIndex];
[self.navigationController setToolbarHidden:YES animated:NO];
NSURL *url = [NSURL URLWithString: selectedObject.url];
locationDetailViewController *locationDetailView;
locationDetailView = [[locationDetailViewController alloc] initWithNibName:#"mapDetailView" bundle:nil];
[self.navigationController pushViewController:locationDetailView animated:YES];
[locationDetailView.webView loadRequest: [NSURLRequest requestWithURL:url]];
[locationDetailView release];
[selectedObject release];
}
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if([[annotation subtitle] isEqualToString:#"Academic"])
{
// try to dequeue an existing pin view first
static NSString* annotationIdentifier = #"annotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!pinView)
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:annotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
UIImage *academicImage = [UIImage imageNamed:#"academic.png"];
CGRect resizeRect;
resizeRect.size = academicImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[mapViewController annotationPadding],
[mapViewController annotationPadding]).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [mapViewController calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[academicImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSInteger annotationValue = [self.mapAnnotations indexOfObject:annotation];
rightButton.tag = annotationValue;
[rightButton addTarget:self action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
else if([[annotation subtitle] isEqualToString:#"Administrative"])
{
// try to dequeue an existing pin view first
static NSString* annotationIdentifier = #"annotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!pinView)
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:annotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
UIImage *administrativeImage = [UIImage imageNamed:#"administrative.png"];
CGRect resizeRect;
resizeRect.size = administrativeImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[mapViewController annotationPadding],
[mapViewController annotationPadding]).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [mapViewController calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[administrativeImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSInteger annotationValue = [self.mapAnnotations indexOfObject:annotation];
rightButton.tag = annotationValue;
[rightButton addTarget:self action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
else if([[annotation subtitle] isEqualToString:#"University Housing"] || [[annotation subtitle] isEqualToString:#"Residence Halls"] || [[annotation subtitle] isEqualToString:#"University Duplexes"] || [[annotation subtitle] isEqualToString:#"Greek Housing"])
{
// try to dequeue an existing pin view first
static NSString* annotationIdentifier = #"annotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!pinView)
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:annotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
UIImage *housingImage = [UIImage imageNamed:#"housing.png"];
CGRect resizeRect;
resizeRect.size = housingImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[mapViewController annotationPadding],
[mapViewController annotationPadding]).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [mapViewController calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[housingImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSInteger annotationValue = [self.mapAnnotations indexOfObject:annotation];
rightButton.tag = annotationValue;
[rightButton addTarget:self action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
else if([[annotation subtitle] isEqualToString:#"Other"])
{
// try to dequeue an existing pin view first
static NSString* annotationIdentifier = #"annotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!pinView)
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:annotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
UIImage *otherImage = [UIImage imageNamed:#"other.png"];
CGRect resizeRect;
resizeRect.size = otherImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[mapViewController annotationPadding],
[mapViewController annotationPadding]).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [mapViewController calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[otherImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSInteger annotationValue = [self.mapAnnotations indexOfObject:annotation];
rightButton.tag = annotationValue;
[rightButton addTarget:self action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
else if([[annotation subtitle] isEqualToString:#"Fields"])
{
// try to dequeue an existing pin view first
static NSString* annotationIdentifier = #"annotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!pinView)
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:annotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
UIImage *athleticsImage = [UIImage imageNamed:#"athletics.png"];
CGRect resizeRect;
resizeRect.size = athleticsImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[mapViewController annotationPadding],
[mapViewController annotationPadding]).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [mapViewController calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[athleticsImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSInteger annotationValue = [self.mapAnnotations indexOfObject:annotation];
rightButton.tag = annotationValue;
[rightButton addTarget:self action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
else if([[annotation subtitle] isEqualToString:#"Landmarks"])
{
// try to dequeue an existing pin view first
static NSString* annotationIdentifier = #"annotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!pinView)
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:annotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
UIImage *landmarkImage = [UIImage imageNamed:#"landmark.png"];
CGRect resizeRect;
resizeRect.size = landmarkImage.size;
CGSize maxSize = CGRectInset(self.view.bounds,
[mapViewController annotationPadding],
[mapViewController annotationPadding]).size;
maxSize.height -= self.navigationController.navigationBar.frame.size.height + [mapViewController calloutHeight];
if (resizeRect.size.width > maxSize.width)
resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
if (resizeRect.size.height > maxSize.height)
resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[landmarkImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSInteger annotationValue = [self.mapAnnotations indexOfObject:annotation];
rightButton.tag = annotationValue;
[rightButton addTarget:self action:#selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
return nil;
}
#pragma mark <mapParser> Implementation
- (void)parser:(NSXMLParser *)parser didFailWithError:(NSError *)parseError {
}
- (void)parserDidEndParsingData:(mapParser *)parser
{
[self addAnnotation];
tabView.mapAnnotations2 = mapAnnotations;
self.mParser = nil;
[mParser release];
}
- (void)parser:(mapParser *)parser didParseItem:(NSArray *)parsedItem
{
NSLog(#"Did Parse Map Item");
[self.mapAnnotations addObjectsFromArray:parsedItem];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {}
#end
Most likely these three classes are missing from your project file. Check the Classes group in your XCode project to see if these three files are present. If not, then right-click the Classes group, and click Add > Existing Files to add them.
If the files are added to the project, then make sure that the implementation (.m) files for these missing classes are added to compiled sources. To check that, expand the group Targets > your application target > Compile Sources, and see if the files are present. If not, right click on "Compile Sources", and goto Add > Existing Files to add them. An alternative and maybe quicker way to do the same is by selecting the .m files for each of the missing classes, and see if the bulls eye checkbox on the far right is checked. If not, then check it and it will automatically get added to Compiled Sources.
"_OBJC_CLASS_$_mapListViewController", referenced from:
objc-class-ref-to-mapListViewController in mapViewController.o
"_OBJC_CLASS_$_mapParser", referenced from:
objc-class-ref-to-mapParser in mapViewController.o
"_OBJC_CLASS_$_mapTabViewController", referenced from:
objc-class-ref-to-mapTabViewController in mapViewController.o
ld: symbol(s) not found collect2: ld returned 1 exit status
Make sure all (mapListViewController,mapParser,mapTabViewController) have both #interface & #implementation
this solve my issue. i happen to miss look #implementation was missing
I was having the same issue which I resolved by adding the Framework into xCode
when you add CoreGraphics libraray.you need to select project_name->targets/select project name (not select project test name,its an error you face)->buildsetting->and add CoreLocation.framework
I was having this problem when I was trying to have pod 'FirebaseRemoteConfig inside app extensions. I added $(inherited) instead of -ObjC to Other Linker Flags in the Build Settings of the Extension target.
I hope it helps anyone out there. I have lost 1 hour finding this solution.