Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:17:48+00:00 2026-05-30T02:17:48+00:00

For some reason the code below is not adding annotations to the map view.

  • 0

For some reason the code below is not adding annotations to the map view. When I log out a count it returns 0, although it goes through the array almost 50 times. The Attraction object implements the MKAnnotation protocol.

-(void)forwardGeocoderFoundLocation
{
int searchResults = [attractions count];
for(int i = 0; i < searchResults; i++){
    Attraction *a = [[Attraction alloc] init];
    a.address = [(Attraction *)[attractions objectAtIndex:i] address];
    a.city = [(Attraction *)[attractions objectAtIndex:i] city];
    a.state = [(Attraction *)[attractions objectAtIndex:i] state];

    NSString *address = [NSString stringWithFormat:@"%@,%@,%@", a.address, a.city, a.state];

    NSString *theAddress = [address stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

    NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", theAddress];

    NSString *locationString = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:urlString] usedEncoding:nil error:nil];

    //NSLog(@"%@", locationString);

    [[attractions objectAtIndex:i] setLocation:[[CLLocation alloc] initWithLatitude:43.1330340 longitude:-77.6376329]];

    NSLog(@"Attraction location = %@", [[attractions objectAtIndex:i] location]);

    [self.mv addAnnotation:[self.attractions objectAtIndex:i]];

    NSLog(@"Mapview has %i annotations.", self.mv.annotations.count);

}

}

Here’s the Attraction.h file:

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface Attraction : NSObject<MKAnnotation>

@property(nonatomic,assign)int attractionID;
@property(nonatomic,copy)NSString *name;
@property(nonatomic,copy)NSString *address;
@property(nonatomic,copy)NSString *description;
@property(nonatomic,copy)NSString *city;
@property(nonatomic,copy)NSString *state;
@property(nonatomic,copy)CLLocation *location;

+ (id)attraction;
- (id)initWithID:(int)a_id name:(NSString *)a_name address:(NSString *)a_address description:(NSString*)a_description city:(NSString*)a_city state:(NSString *)a_state;

@end

And here’s the Attraction.m file:

#import "Attraction.h"

@implementation Attraction

@synthesize attractionID, name, address, description, city, state, location;

- (CLLocationCoordinate2D)coordinate{
return self.location.coordinate;
}

- (NSString *)title{
return self.name;
}

- (NSString *)subtitle{
return self.name;
}

#pragma mark - 
+ (id)attraction {
return [[Attraction alloc] init ];
}

- (id)initWithID:(int)a_id name:(NSString *)a_name address:(NSString *)a_address description:(NSString*)a_description city:(NSString*)a_city state:(NSString *)a_state {

self = [super init];
self.attractionID = a_id;
self.address = a_address;
self.name = a_name;
self.description = a_description;
self.city = a_city;
self.state = a_state;

return self;

}

- (id)init
{
return [self initWithID:0 name:@"TBD" address:@"TBD" description:@"TBD" city:@"TBD"  state:@"TBD"];
}

@end

Any help would be appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:17:50+00:00Added an answer on May 30, 2026 at 2:17 am

    if self.mv is nil, as you confirmed, then self.mv.annotations.count return nil (or 0, or something like that). And that is logged as 0 when you format it as "%i".

    But there is nothing in the code you submitted can cause it to be nil, so you must look for the reason in other parts of your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason the code I have included below does not interpolate the variables
For some reason the code below is returning the results, put not in the
For some reason this PHP code below will not work, I can not figure
See code below, for some reason it only works when I put a breakpoint
For some reason i'm getting an unexpected [ in the below line of code.
For some reason, this code does not actually draw my bitmap file... or show
For some reason the code below when I iterate through some urls, curl_exec never
The below code is bound to a button. For some reason the below code
I am leaning some Java for school, and for some reason the code below
I'm creating a javascript framework, and the code below is not working for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.