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 7947239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:22:31+00:00 2026-06-04T01:22:31+00:00

I just wanted to add a Polyline to my Map which is displayed in

  • 0

I just wanted to add a Polyline to my Map which is displayed in a tableviewcell. Unfortunately
the delegate methods are not called… Would be nice if someone knows why.

My tableview.h:

#import <UIKit/UIKit.h>
#import "Route.h"
#import <MapKit/MapKit.h>
#import <QuartzCore/QuartzCore.h>

@interface RoutesDetailView : UITableViewController<MKMapViewDelegate>{
    Route *myRoute;
    MKMapView *mapView;
    // the view we create for the line on the map
    MKPolylineView* _routeLineView;

    // the rect that bounds the loaded points
    MKMapRect _routeRect;
    MKPolyline* _routeLine;
}

@property (nonatomic, retain) Route *myRoute;
@property (nonatomic,retain) MKMapView *mapView;
@property (nonatomic, retain) MKPolyline* routeLine;
@property (nonatomic, retain) MKPolylineView* routeLineView;

-(MKPolyline *) loadRoute: (Route *) theRoute;
@end

And my tableview.m:

    @implementation RoutesDetailView
    @synthesize myRoute,mapView;
    @synthesize routeLine = _routeLine;
    @synthesize routeLineView = _routeLineView;

    - (id)initWithStyle:(UITableViewStyle)style
    {
        self = [super initWithStyle:style];
        if (self) {
            // Custom initialization
        }
        return self;
    }

    - (void)didReceiveMemoryWarning
    {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];

        // Release any cached data, images, etc that aren't in use.
    }

    #pragma mark - View lifecycle

    - (void)viewDidLoad
    {    
        [super viewDidLoad];
        MKMapView *myMap = [[MKMapView alloc] initWithFrame:CGRectMake(10, 1, 300 , 300)];
        myMap.layer.cornerRadius = 10.0;
        [self setMapView:myMap];
        [mapView setDelegate:self];
        CLLocationCoordinate2D annotationCoord;
        annotationCoord.latitude = [[NSString stringWithFormat:@"%@",NSLocalizedString(@"DefaultPointLAT", nil)] doubleValue];
        annotationCoord.longitude = [[NSString stringWithFormat:@"%@",NSLocalizedString(@"DefaultPointLONG", nil)] doubleValue];
        MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
        annotationPoint.coordinate = annotationCoord;
        MKCoordinateRegion region =
        MKCoordinateRegionMakeWithDistance (annotationPoint.coordinate,[[NSString stringWithFormat:@"%@",NSLocalizedString(@"DefaultCircle", nil)] doubleValue], [[NSString stringWithFormat:@"%@",NSLocalizedString(@"DefaultCircle", nil)] doubleValue]);
        [mapView setRegion:region animated:NO];
        // Uncomment the following line to preserve selection between presentations.
        // self.clearsSelectionOnViewWillAppear = NO;

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    }

    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    }

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    }

    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    }

    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

    #pragma mark - Table view data source


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
.
.
.

            static NSString *CellIdentifier = @"CellMap";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            [mapView setFrame:CGRectMake(10, 1, cell.frame.size.width-20 , cell.frame.size.height-1)];
            [cell addSubview:mapView];
            [mapView addOverlay:[self loadRoute:myRoute]];
            return cell;
.
.
.

    }




    #pragma mark - Table view delegate
    -(MKPolyline *) loadRoute: (Route *) theRoute
    {

        MKMapPoint northEastPoint;
        MKMapPoint southWestPoint; 

        // create a c array of points.
        MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * theRoute.latitude.count);

        for(int idx = 0; idx < theRoute.latitude.count; idx++)
        {

            CLLocationDegrees latitude = [[[theRoute latitude] objectAtIndex:idx] doubleValue];
            CLLocationDegrees longitude = [[[theRoute longitude] objectAtIndex:idx] doubleValue];

            // create our coordinate and add it to the correct spot in the array
            CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);

            MKMapPoint point = MKMapPointForCoordinate(coordinate);

            //
            // adjust the bounding box
            //

            // if it is the first point, just use them, since we have nothing to compare to yet.
            if (idx == 0) {
                northEastPoint = point;
                southWestPoint = point;
            }
            else
            {
                if (point.x > northEastPoint.x)
                    northEastPoint.x = point.x;
                if(point.y > northEastPoint.y)
                    northEastPoint.y = point.y;
                if (point.x < southWestPoint.x)
                    southWestPoint.x = point.x;
                if (point.y < southWestPoint.y)
                    southWestPoint.y = point.y;
            }

            pointArr[idx] = point;

        }

        // create the polyline based on the array of points.
        self.routeLine = [MKPolyline polylineWithPoints:pointArr count:theRoute.latitude.count];

        _routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);

        // clear the memory allocated earlier for the points
        free(pointArr);
        return self.routeLine;


    }

    - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay
    {
        NSLog(@"DELEGATE CALL");
        MKOverlayView* overlayView = nil;

        if(overlay == self.routeLine)
        {
            //if we have not yet created an overlay view for this overlay, create it now.
            if(nil == self.routeLineView)
            {
                self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
                self.routeLineView.fillColor = [UIColor redColor];
                self.routeLineView.strokeColor = [UIColor redColor];
                self.routeLineView.lineWidth = 15;
            }

            overlayView = self.routeLineView;

        }

        return overlayView;

    }


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Navigation logic may go here. Create and push another view controller.
        /*
         <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
         // ...
         // Pass the selected object to the new view controller.
         [self.navigationController pushViewController:detailViewController animated:YES];
         */
    }

    @end
  • 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-04T01:22:32+00:00Added an answer on June 4, 2026 at 1:22 am

    Try this, I was having the same issue. After trying many combinations this is the one which works.

    #import <UIKit/UIKit.h>
    #import <MapKit/MapKit.h>
    
    @interface MapViewController : UIViewController<MKMapViewDelegate> {
    
        MKMapView   *mapView;
    }
    

    and the implementation…

    - (void)viewDidLoad {
    
        [super viewDidLoad];
    
        mapView = [[MKMapView alloc] initWithFrame: CGRectMakeFullScreenIphone];
        mapView.delegate = self;
        [mapView setMapType: MKMapTypeStandard];
        [self.view addSubview: mapView]; 
    
    
        MKCoordinateRegion newRegion;
        // configure region...
        [mapView setRegion:newRegion animated:YES];
    
        CLLocationCoordinate2D coordinate;
        //configure coordinate...
    
        MKPointAnnotation *annotation = [[MKPointAnnotation alloc]init];
        [annotation setCoordinate:coordinate];
        [annotation setTitle:@"TEST"];
        [mapView addAnnotation:annotation];
    }
    

    The simple code above works fine and delegate’s methods were called.

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

Sidebar

Related Questions

today I just opened my 1,5 month old project and wanted to add a
Just wanted to know how i would replace sitename.com with sitename2.com whenever a user
Just wanted to know if overriding UITabBarController would get my app rejected? Is it
I just wanted to confirm, is it possible that we add layers of images
Note: I will be answering my own question... just wanted to add this tidbit
just wanted to add this Color Picker ( http://code.google.com/p/devmil-android-color-picker/source/browse/ ) to my app and
How much overhead does Mongoose add to the node-mongodb-native driver? If I just wanted
I have a working recommend to script, I just wanted to add a extra
Just wanted to know if i am going in the right direction or not.
Update: 24 Mar 2011: Just wanted to add that I've had a look at

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.