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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:33:23+00:00 2026-06-18T02:33:23+00:00

Hi everyone I hope you can help me: – (IBAction) addPoints: (id) sender {

  • 0

Hi everyone I hope you can help me:

- (IBAction) addPoints: (id) sender
{
NSArray *latitudePoints;
NSArray *longitudePoints;
BOOL flag = NO;
@try
{
switch (lugar)
{
    case 0:
        break;

    case 1:
        latitudePoints = @[@27.781361, @27.777894, @27.766683, @27.757066, @27.745613, @27.737327, @27.728247, @27.720827, @27.720866, @27.719083, @27.722266, @27.721097, @27.739263, @27.758177, @27.780688];
        longitudePoints = @[@-15.714188, @-15.720175, @-15.726072, @-15.740874, @-15.746066, @-15.759544, @-15.763944, @-15.774408, @-15.764822, @-15.752658, @-15.735975, @-15.715497, @-15.718150, @-15.712244, @-15.713213];
        flag = YES;
        break;

    case 2:
        latitudePoints = @[@28.249792, @28.254583, @28.259865, @28.264000, @28.265621, @28.267694, @28.270308, @28.272192, @28.273966, @28.275698, @28.277723, @28.279901];
        longitudePoints = @[@-16.841880, @-16.842477, @-16.842657, @-16.844832, @-16.848396, @-16.851215, @-16.852329, @-16.856142, @-16.859281, @-16.860882, @-16.862011, @-16.863116];
        flag = YES;
        break;

    default:
        [NSException raise:@"Unknown place" format:@"Unknown place"];
        break;
}
// NSLog(@"Lugar %d Flag %d",lugar,flag);
if (flag && [longitudePoints count] == [latitudePoints count])
{
    anotacionesMapa *point; // anotacionesMapa is a custom MKAnnotation class, just have title, subtitle and coord atribute
    CLLocationCoordinate2D placePoint;
    NSMutableArray *pointList = [[NSMutableArray alloc] initWithCapacity:[longitudePoints count]];
    for (int c = 0; c < [longitudePoints count]; c++)
    {
        placePoint.latitude = [[latitudePoints objectAtIndex:c] doubleValue];
        placePoint.longitude = [[longitudePoints objectAtIndex:c] doubleValue];
        if (c % 2 == 0)
            point = [[anotacionesMapa alloc] initWithTitle:[NSString stringWithFormat:@"[Picture here] Nothing"]
                                                  subtitle:@""
                                             andCoordinate: placePoint];
        else
            point = [[anotacionesMapa alloc] initWithTitle:[NSString stringWithFormat:@"Something"]
                                                  subtitle:@"[Pic here] test"
                                             andCoordinate: placePoint];
        [self.mapView addAnnotation:point];
        CLLocation *linePoint = [[CLLocation alloc] initWithLatitude:placePoint.latitude longitude:placePoint.longitude];
        [pointList addObject: linePoint];
    }
    ruta = [[CSMapRouteLayerView alloc] initWithRoute:pointList
                                              mapView:self.mapView];
}
}
@catch (NSException *exception)
{
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:@"Error..."
                                   message:[NSString stringWithFormat:@"%@", exception]
                                  delegate:self
                         cancelButtonTitle:@"Aceptar"
                         otherButtonTitles:nil];
[alert show];
}
}

I have this code, then I need to print lines between that coordinates from PuntosLT and PuntosLG that store latitudes and longitudes, but when it suppouse to print the lines (that lines are printed actually, in blue color, I want to print in red color) the MKMapView get frozen and can’t move around and can’t zoom, and I think it get bugs and draw other lines that is not in the coords, and finally my custom images in my anotations are red pins again, like default and the information like title, subtitle doesn’t work.

Thanks.

EDIT: The Method/Constructor

-(id) initWithRoute:(NSArray*)routePoints mapView:(MKMapView*)mapView
{
self = [super initWithFrame:CGRectMake(0, 0, mapView.frame.size.width, mapView.frame.size.height)];
[self setBackgroundColor:[UIColor clearColor]];

[self setMapView:mapView];
[self setPoints:routePoints];

// determine the extents of the trip points that were passed in, and zoom in to that area. 
CLLocationDegrees maxLat = -90;
CLLocationDegrees maxLon = -180;
CLLocationDegrees minLat = 90;
CLLocationDegrees minLon = 180;

for(int idx = 0; idx < self.points.count; idx++)
{
    CLLocation* currentLocation = [self.points objectAtIndex:idx];
    if(currentLocation.coordinate.latitude > maxLat)
        maxLat = currentLocation.coordinate.latitude;
    if(currentLocation.coordinate.latitude < minLat)
        minLat = currentLocation.coordinate.latitude;
    if(currentLocation.coordinate.longitude > maxLon)
        maxLon = currentLocation.coordinate.longitude;
    if(currentLocation.coordinate.longitude < minLon)
        minLon = currentLocation.coordinate.longitude;
}

MKCoordinateRegion region;
region.center.latitude     = (maxLat + minLat) / 2;
region.center.longitude    = (maxLon + minLon) / 2;
region.span.latitudeDelta  = maxLat - minLat;
region.span.longitudeDelta = maxLon - minLon;

[self.mapView setRegion:region];
[self.mapView setDelegate:self];
[self.mapView addSubview:self];

return self;
}
  • 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-18T02:33:25+00:00Added an answer on June 18, 2026 at 2:33 am

    I fixed using some new variables from apple mapkit, I removed CSMapRouteLayerView lib. I added:

    MKPolyline *routeLine;
    MKPolylineView *routeLineView;
    

    and this code in my question method to add lines:

    - (IBAction) addPuntos: (id) sender
    {
    NSArray *puntosLt;
    NSArray *puntosLg;
    BOOL flag = NO;
    @try
    {
        switch (lugar)
        {
            case 0:
                break;
    
            case 1:
                puntosLt = @[@27.781361, @27.777894, @27.766683, @27.757066, @27.745613, @27.737327, @27.728247, @27.720827, @27.720866, @27.719083, @27.722266, @27.721097, @27.739263, @27.758177, @27.780688];
                puntosLg = @[@-15.714188, @-15.720175, @-15.726072, @-15.740874, @-15.746066, @-15.759544, @-15.763944, @-15.774408, @-15.764822, @-15.752658, @-15.735975, @-15.715497, @-15.718150, @-15.712244, @-15.713213];
                flag = YES;
                break;
    
            case 2:
                puntosLt = @[@28.249792, @28.254583, @28.259865, @28.264000, @28.265621, @28.267694, @28.270308, @28.272192, @28.273966, @28.275698, @28.277723, @28.279901];
                puntosLg = @[@-16.841880, @-16.842477, @-16.842657, @-16.844832, @-16.848396, @-16.851215, @-16.852329, @-16.856142, @-16.859281, @-16.860882, @-16.862011, @-16.863116];
                flag = YES;
                break;
    
            default:
                [NSException raise:@"Lugar desconocido" format:@"Lugar desconocido"];
                break;
        }
        // NSLog(@"Lugar %d Flag %d",lugar,flag);
        if (flag && [puntosLg count] == [puntosLt count])
        {
            anotacionesMapa *punto;
            CLLocationCoordinate2D lugarPunto;
            CLLocationCoordinate2D puntitos[[puntosLg count]];
            for (int c = 0; c < [puntosLg count]; c++)
            {
                lugarPunto.latitude = [[puntosLt objectAtIndex:c] doubleValue];
                lugarPunto.longitude = [[puntosLg objectAtIndex:c] doubleValue];
                punto = [[anotacionesMapa alloc] initWithTitle:[NSString stringWithFormat:@"[Foto barco] Sin avistamientos"]
                                                      subtitle:@""
                                                 andCoordinate: lugarPunto];
                [self.mapView addAnnotation:punto];
                puntitos[c] = CLLocationCoordinate2DMake(lugarPunto.latitude, lugarPunto.longitude);
            }
            self.routeLine = [MKPolyline polylineWithCoordinates:puntitos count:[puntosLg count]];
            [self.mapView setVisibleMapRect: [self.routeLine boundingMapRect]];
            [self.mapView addOverlay: self.routeLine];
        }
    }
    @catch (NSException *exception)
    {
        UIAlertView *alert;
        alert = [[UIAlertView alloc] initWithTitle:@"Error..."
                                           message:[NSString stringWithFormat:@"%@", exception]
                                          delegate:self
                                 cancelButtonTitle:@"Aceptar"
                                 otherButtonTitles:nil];
        [alert show];
    }
    }
    

    PD: I will not use @try/@catch, this is a sample app for me using MKMapView so I will keep them in this mini project, the rest I will follow http://developer.apple.com/library/ios/#Documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorHandling/ErrorHandling.html

    Thanks.

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

Sidebar

Related Questions

HI everyone I hope you can help me, I have a problem with a
hope everything's great with everyone. can someone please help me to create regexp to
I hope you can help me; How to convert a urlcode in array in
I hope someone here can help me. I know that in IE 9, there
EDIT Everyone can try to make an emulator for this phone http://www.gsmarena.com/htc_chacha-3787.php to see
i hope that everyone here know the php 'variable variable' syntax: $color = 'red';
I want to change the delimiter: Can someone help me to change the delimiter
Morning all, hope everyone is ok. I have an ODS that uses a combination
Hey everyone ;) I have a new question again :D I can open my
Good morning everyone, I hope I'm not posting this in the wrong place; I've

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.