Return to Snippet

Revision: 70201
at December 10, 2015 03:02 by TenDegrees


Initial Code
- (void) onUnityLocations:(NSDictionary *)locations
{

    for(NSNumber *key in [locations allKeys])
    {
        ProfileLocation *affiliateLocation = [locations objectForKey:key];
        
        if(![self.unityAffiliateMarkers objectForKey:key]) // the users profile and location has not been cached yet
        {
            Profile *affiliateProfile = [[Profile alloc]init];
            affiliateProfile.entityId = affiliateLocation.profileId;
            if(!affiliateProfile.entityId==0)
            {
                [self readUnityObject:affiliateProfile withCompletionBlock:^(id object, bool success, NSString * errorMessage)
                 {
                     if(success) // generate a GMSMarker containing the profile object
                     {
                         GMSMarker *affiliateLocationMarker = [GMSMarker markerWithPosition:CLLocationCoordinate2DMake(affiliateLocation.latitude, affiliateLocation.longitude)];
                         affiliateLocationMarker.flat = YES;
                         affiliateLocationMarker.zIndex = -1;
                         affiliateLocationMarker.appearAnimation=kGMSMarkerAnimationPop;
                         affiliateLocationMarker.groundAnchor = CGPointMake(0.5, 0.5);
                         [affiliateLocationMarker setUserData:((Profile *)object)]; // this sets the profile to the marker
                         affiliateLocationMarker.icon= [TenDegreesHelpers roundImageCorners:[self applyAlpha:1 toImage:[self image:[TenDegreesHelpers stringToUIImage:((Profile *)object).icon] scaledToSize:CGSizeMake(30.0f, 30.0f)]]];
                         
                         if(![self.unityAffiliateMarkers objectForKey:key]) // check again to prevent duplicate locations
                         {
                         	affiliateLocationMarker.map=self.googleMap;
                         	[self.unityAffiliateMarkers setObject:affiliateLocationMarker forKey:key];
                         }
                     }
                     else
                     {
                         NSLog(@"%@",errorMessage);
                     }
                 }];
            }

        }
        else // users location and profile are already cached - just update their location on the map
        {
            GMSMarker *affiliateLocationMarker = [self.unityAffiliateMarkers objectForKey:key];
            [affiliateLocationMarker setPosition:CLLocationCoordinate2DMake(affiliateLocation.latitude, affiliateLocation.longitude)];
            
        }
        
    }
    for(NSNumber *key in [self.unityAffiliateMarkers allKeys])
    {
        if(![locations objectForKey:key]) // remove any markers of users who have logged out or timed out
        {
            GMSMarker *affiliateLocationMarker = [self.unityAffiliateMarkers objectForKey:key];
            affiliateLocationMarker.map=nil;
            [self.unityAffiliateMarkers removeObjectForKey:key];
        }
    }
    [_extendUpdateDelegate onLocations:locations];
}

Initial URL

                                

Initial Description
How to manage and update user locations using the onUnityLocations delegate.

Initial Title
Updating, Managing, and Displaying User Locations

Initial Tags
user

Initial Language
Objective C