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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:05:22+00:00 2026-06-15T13:05:22+00:00

Im adding a bunch of annotations, and sotirng them in an array so i

  • 0

Im adding a bunch of annotations, and sotirng them in an array so i can pull in their new locations and update the map accordingly WITHOUT removing all the annotations first and adding them which causes a flicker. Unfortunately, after their coordinates are initially set and added any setCoordinate call no longer works. Any ideas?

- (void)updateMap:(NSData *)responseData {
    //parse out the JSON data
    NSError* error;
    vehicleData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

    //find which Dictionary is for our bus.
    for (NSDictionary* route in vehicleData) {
        //find our bus in our vehicles dictionary. Key is by routeID.
        BusPositionDot *busLocationDot; 
        if ([vehicles objectForKey:[route objectForKey:@"RouteID"]] == nil) {
            busLocationDot = [[BusPositionDot alloc] init];
            [vehicles setObject:busLocationDot forKey:[route objectForKey:@"RouteID"]];
            [mapView addAnnotation:[vehicles objectForKey:[route objectForKey:@"RouteID"]]];

        }
        else {
            busLocationDot = [vehicles objectForKey:@"RouteID"];
        }

        float latitude = [[route objectForKey:@"Latitude"] floatValue];
        float longitude = [[route objectForKey:@"Longitude"] floatValue];
        float groundSpeed = [[route objectForKey:@"GroundSpeed"] floatValue];
        float direction = [[route objectForKey:@"Heading"] floatValue];

        float roundedDirection=45 * round(direction/45);

        if(groundSpeed<=3)
            //get view for annotation
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot.png"];
        else if((roundedDirection==0)||(roundedDirection==360))
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot0.png"];
        else if(roundedDirection==45)
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot45.png"];
        else if(roundedDirection==90)
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot90.png"];
        else if(roundedDirection==135)
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot135.png"];
        else if(roundedDirection==180)
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot180.png"];
        else if(roundedDirection==225)
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot225.png"];
        else if(roundedDirection==270)
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot270.png"];
        else if(roundedDirection==315)
            [mapView viewForAnnotation:busLocationDot].image=[UIImage imageNamed:@"buspositiondot315.png"];

        CLLocationCoordinate2D currentBusLocation = CLLocationCoordinate2DMake(latitude, longitude);
        NSLog(@"setting coord %f & %f",currentBusLocation.latitude,currentBusLocation.longitude);

        [UIView animateWithDuration:0.5 animations:^{
            [busLocationDot setCoordinate:currentBusLocation];

        }];
    }
}
  • 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-15T13:05:23+00:00Added an answer on June 15, 2026 at 1:05 pm

    In reference to this part:

    if ([vehicles objectForKey:[route objectForKey:@"RouteID"]] == nil) {
        ...
        [mapView addAnnotation:
            [vehicles objectForKey:[route objectForKey:@"RouteID"]]];
    }
    else {
        busLocationDot = [vehicles objectForKey:@"RouteID"];
    }
    

    when you call addAnnotation, you pass:

    [vehicles objectForKey:[route objectForKey:@"RouteID"]]
    

    but if it already exists, you use:

    [vehicles objectForKey:@"RouteID"]
    

    This means when updating an annotation, a different (most likely wrong) reference is being used.
    Either [vehicles objectForKey:@"RouteID"] is not actually a BusPositionDot or it’s not the same instance that was originally added with that “route id”.

    Therefore, the setCoordinate wouldn’t work.
    Using the same reference when updating the annotation should fix it.

    There are a couple of other unrelated, potential issues:

    • The code is doing a direct comparison using a float variable (eg. if(roundedDirection==45)). This is not recommended even if it “seems to work” — there’s the potential for floating-point precision errors. Either check if roundedDirection is within a very small range of the target value or, in your case, just declare roundedDirection as an int since it looks like the expression
      45 * round(direction/45) will only return values with no fractions.

    • The code is setting the image of the annotation view directly. This is ok but make sure the viewForAnnnotation delegate method also has the same exact logic to set the image based on direction otherwise what may happen is the annotation view’s image will get reset to some default when panning or zooming. You may need to add a direction property to BusPositionDot.

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

Sidebar

Related Questions

I'm a jQuery beginner. I'm adding a bunch of new images into a div.
Adding functionality to a class can be done by adding a method or by
When adding a new data connection in Server Explorer in VS 2010 (with Azure
After a bunch of animating, adding classes and setting css styles. is there an
I have a bunch of users I am adding to conference. They are contained
I have a bunch of custom controls based on a SkinnableContainer. When adding the
I'm adding a new WPF project to an existing Visual Studio solution and would
I'm adding a bunch of QAction s to my main window's menus. These actions
I've got a view which is adding a bunch of data into a bound
I am a adding a couple of simple elements to a bunch of XML

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.