Search code examples
iosobjective-cskobbler-maps

Current Location SKPulseAnimation does not work


I am doing one function, when users pressed a button, map will indicate users' current location by on pulse animation annotation.

SKCoordinateRegion region;
region.center = CLLocationCoordinate2DMake(_currentLocation.coordinate.latitude, _currentLocation.coordinate.longitude);
region.zoomLevel = 14;
self.mapView.visibleRegion = region;

SKAnnotation *CurrentLocationAnnotation = [SKAnnotation annotation];
CurrentLocationAnnotation.identifier = 1;
//CurrentLocationAnnotation.annotationType = SKAnnotationTypeMarker;
CurrentLocationAnnotation.location = CLLocationCoordinate2DMake(_currentLocation.coordinate.latitude, _currentLocation.coordinate.longitude);
SKAnimationSettings *CurrentLocationanimationSettings = [SKAnimationSettings animationSettings];
CurrentLocationanimationSettings.animationType = SKPulseAnimation;
CurrentLocationanimationSettings.animationEasingType = SKAnimationEaseLinear;
CurrentLocationanimationSettings.duration = 7000;
[self.mapView addAnnotation:CurrentLocationAnnotation withAnimationSettings:CurrentLocationanimationSettings];

I tried it on simulator and iphone as well, both of them don't work at all. How can i fix it? thanks in advance


Solution

  • CLLocationCoordinate2D cordinate;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.mapview.delegate=self;
        self.locationManager.delegate = self
        self.locationManager.distanceFilter = kCLDistanceFilterNone
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        [self.mapview setMapType:MKMapTypeSatellite];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 54, 122, 21)];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        label.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.3];
        label.text = @"title";
    
        //create our view for the image
         UIImageView *coloredView1 = [[UIImageView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
        coloredView1.image = [UIImage imageNamed:@"demo.png"];
        UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
        view1.backgroundColor = [UIColor clearColor];
        [view1 addSubview:label];
        [view1 addSubview:coloredView1];
    
         //create our view for the background image
        UIImageView *coloredView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0.0, 136, 110)];
        coloredView2.image = [UIImage imageNamed:@"mapMarker"];
        UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(7, 5.5, 122, 75)];
        view1.backgroundColor = [UIColor clearColor];
        [view2 addSubview:coloredView2];
        [view2 addSubview:view1];
    
        //create our view for the background image
    
       UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0.0, 136, 200)];
        view3.backgroundColor = [UIColor clearColor];
        [view3 addSubview:view2];
    
        SKAnnotationView *annotationView = [[SKAnnotationView alloc] initWithView:customAnnotationView reuseIdentifier:@"reusableIdentifier"];
    
        SKAnnotation *annotation = [SKAnnotation annotation];
        annotation.identifier = 123456;
        annotation.location = region.center;
        annotation.annotationView = annotationView;
    
        [self.mapView addAnnotation:annotation withAnimationSettings:[SKAnimationSettings animationSettings]];
    
    }
    
    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
    {
        if([annotation isKindOfClass:[MKUserLocation class]])
        {
            return nil;
        }
        static NSString *identifier = @"myAnnotation";
        DraggableAnnotationView * annotationView = (DraggableAnnotationView *)[self.mapview dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (!annotationView)
        {
            annotationView = [[DraggableAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            annotationView.image = [UIImage imageNamed:@"ic_map_pin.png"];
        }
        else
        {
            annotationView.annotation = annotation;
        }
        annotationView.delegate = self;
    
        return annotationView;
    }
    

    if this code helpful for you then give your vote ... thank you