Search code examples
iosparse-platformmapkitmkannotationview

Annotating a mapview based on type, using Parse Query


I am developing an app that uses Parse, and I am trying to lay custom annotation images based on a location's type.

In ViewForAnnotation I have the following:

    CustomStoreAnnotation *ann = (CustomStoreAnnotation *)annotation;
    PFQuery* locationQuery = [PFQuery queryWithClassName:@"tbl_location"];
    [locationQuery whereKey:@"name" equalTo:ann.title];
    [locationQuery findObjectsInBackgroundWithBlock:^(NSArray *locations, NSError *error) {
        if (!error)
        {
            if ([locations count] > 0) 
            {
                //get specific pfobject and set annotation image
            }
            else
            {
                //handle empty array
            }
        }

    }];

This code is working, but an odd behavior occurs where the wrong image appears on the annotationView temporarily at first, but it then fixes itself. Any ideas?


Solution

  • I realized that I did not need this query at all because I could instead associate a type with each annotation when first adding them to the map. This avoids the need for the query entirely, which solved my problem.