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

  • Home
  • SEARCH
  • 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 9084269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:57:34+00:00 2026-06-16T20:57:34+00:00

I am trying to loop through the addresses i have in an array, geocode

  • 0

I am trying to loop through the addresses i have in an array, geocode them and add to MKMapview as Annotations.
This the crash i am getting: [LocationAnnotation coordinate]: unrecognized selector sent to instance 0x205ce5c0
Here’s my code:

#import <UIKit/UIKit.h>
#import "MapKit/MapKit.h"
#import <CoreLocation/CoreLocation.h>

@interface LocationAnnotation : NSObject<MKAnnotation>
{
    CLLocationCoordinate2D  coordinate;
    NSString    *mTitle;
    NSString    *mSubTitle;
    NSInteger tag;
}
@property(nonatomic)NSInteger tag;
@end

    @interface RoadmapMerchantMapView : UIView<CLLocationManagerDelegate,MKMapViewDelegate>
    {
        MKMapView * mapView;
        CLLocationManager * currentLocation;
        CLLocationCoordinate2D fuelLocationCoordinate;
        NSString * typeSearch;
        NSArray * allStations;
        LocationAnnotation * stationAnn;
    }


    - (id)initWithFrame:(CGRect)frame withData:(NSArray *)data;
    @end

#import "RoadmapMerchantMapView.h"

@implementation LocationAnnotation

-(NSString *) title
{
    return mTitle;
}

-(NSString *) subtitle
{
    return mSubTitle;
}

-(id)initWithCoordinate:(CLLocationCoordinate2D)Mycoordinate Title:(NSString *)title subTitle:(NSString *)subTitle annIndex:(int)index{
    mTitle = title;
    mSubTitle = subTitle;
    coordinate = Mycoordinate;
    return self;
}

@end

@implementation RoadmapMerchantMapView

- (id)initWithFrame:(CGRect)frame withData:(NSArray *)data
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

    }

    [self layoutLocation:data];
    return self;
}

-(void)zoomToUserLocation:(CLLocationCoordinate2D)userLocation
{
    MKCoordinateRegion region;

    region.center = userLocation;
    region.span = MKCoordinateSpanMake(3.0, 3.0);
    region = [mapView regionThatFits:region];
    [mapView setRegion:region animated:YES];
}


-(void)drawMap {
    mapView = [[MKMapView alloc]initWithFrame:self.bounds];
    mapView.mapType = MKMapTypeStandard;
    mapView.delegate = self;
    [self addSubview:mapView];
}

-(void)layoutLocation:(NSArray*)items
{    
     [self drawMap];

    allStations = [[NSArray alloc]initWithArray:items];
    if ([allStations count]>0) {
        for (int i=0; i<1; i++) {
            NSDictionary * itemNo = [items objectAtIndex:i];

            NSString * fullAddress = [NSString stringWithFormat:@"%@,%@,%@,%@",[itemNo objectForKey:@"address"],[itemNo objectForKey:@"city"],[itemNo objectForKey:@"state"],[itemNo objectForKey:@"zip"]];

            CLGeocoder * geoCoder = [[CLGeocoder alloc]init];
            [geoCoder geocodeAddressString:fullAddress completionHandler:^(NSArray *placemarks, NSError *error) {

                if (error) {
                    NSLog(@"Geocode failed with error: %@", error);
                    return;
                }

                if(placemarks && placemarks.count > 0)
                {
                    CLPlacemark *placemark = placemarks[0];
                    CLLocation *location = placemark.location;
                    CLLocationCoordinate2D coords = location.coordinate;
                    NSLog(@"Latitude = %f, Longitude = %f",
                          coords.latitude, coords.longitude);
                    NSString * name = [itemNo objectForKey:@"name"];
                    stationAnn = [[LocationAnnotation alloc]initWithCoordinate:coords Title:name subTitle:@"Offer" annIndex:i];
                    //stationAnn.tag = i;
                    [mapView addAnnotation:stationAnn];

                }
            }];
        }

    }
    else {

        UIAlertView * av = [[UIAlertView alloc]initWithTitle:@"Not Found" message:@"There are no station in your area. Select state to get more results." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [av show];
        }

}


- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    static NSString * stationLoc = @"stationIdentifier";
    MKPinAnnotationView * customPinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:stationLoc];
    customPinView.pinColor = MKPinAnnotationColorGreen;
    customPinView.animatesDrop = YES;
    customPinView.canShowCallout = YES;

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    NSUInteger index = [(LocationAnnotation *)annotation tag];
    rightButton.tag = index;
    [rightButton addTarget:self
                    action:@selector(showDetails:)
          forControlEvents:UIControlEventTouchUpInside];
    customPinView.rightCalloutAccessoryView = rightButton;

    return customPinView;
}

-(void) showDetails:(id)sender {
    NSLog(@"Tag:%d",[sender tag]);

}
  • 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-06-16T20:57:36+00:00Added an answer on June 16, 2026 at 8:57 pm

    Your LocationAnnotation class doesn’t implement a -coordinate method. You’ve created the instance variable, but not the method returning its value:

    - (CLLocationCoordinate2D)coordinate {
        return coordinate;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having this array. Last few hours I have been trying to loop
I am trying to loop through a directory of text files and combine them
I am trying to loop through this external JSON file(locally stored), but I cannot
Im trying to loop through a json files' object array to access its variables'
I am having trouble trying to loop through a multidimensional array using PHP. When
I am trying to loop through an array and replace values that are in_array
I'm trying to loop through an array that gets returned from a php file.
I'm trying to loop through an array (compare Addr), and find the matching Strings
I'm trying to loop through a list of results from MySQL and display all
I'm trying to loop through objects from my database in the template and one

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.