/ Published in: Objective C
How to manage and update user locations using the onUnityLocations delegate.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
{ { 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)]; } } { 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]; }