Current Location SKPulseAnimation does not work - ios

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

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

Related

not able to tap on MKPinAnnotationView Second Time

I have created Custom annotation by using this code.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *const AnnotatioViewReuseID = #"AnnotatioViewReuseID";
// MKAnnotationView
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotatioViewReuseID];
if (!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotatioViewReuseID];
}
if ([annotation isKindOfClass:[FBAnnotationCluster class]]) {
FBAnnotationCluster *cluster = (FBAnnotationCluster *)annotation;
cluster.title = [NSString stringWithFormat:#"%lu", (unsigned long)cluster.annotations.count];
UIView *view = [[UIView alloc]init];
view.backgroundColor = [UIColor colorWithRed:33.0/255.0 green:191.0/255.0 blue:133.0/255.0 alpha:1.0];
UILabel *label = [[UILabel alloc]init];
label.text = cluster.title;
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.textAlignment = NSTextAlignmentCenter;
UIFont *font = [UIFont fontWithName:#"Avenir-Medium" size:14.0];
label.font = font;
label.frame = CGRectMake(0, 0, [self widthOfString:label.text]+20, [self widthOfString:label.text]+20);
view.frame = CGRectMake(0, 0, label.frame.size.width, label.frame.size.width) ;
view.layer.cornerRadius = view.frame.size.height/2;
view.layer.borderColor = [UIColor whiteColor].CGColor;
view.layer.borderWidth = 2.0;
view.clipsToBounds = true;
[view addSubview:label];
for (UIView *view in [annotationView subviews])
{
[view removeFromSuperview];
}
[annotationView addSubview:view];
annotationView.enabled = YES;
annotationView.annotation = annotation;
annotationView.canShowCallout = YES;
annotationView.pinTintColor = [UIColor clearColor];
} else {
annotationView.pinTintColor = [UIColor clearColor];
annotationView.layer.borderColor = [UIColor clearColor].CGColor;
annotationView.layer.borderWidth = 0.0;
FBAnnotation *a = (FBAnnotation*)annotation;
NSLog(#"amount is %f",a.amount);
UIImage *image = [UIImage imageNamed:#"icon-marker-select"];
UIImageView *imgView = [[UIImageView alloc]init];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
formatter.maximumFractionDigits = 2;
NSString *result = [formatter stringFromNumber:[NSNumber numberWithDouble:a.amount]];
NSString *strData = [NSString stringWithFormat:#"%#%#",a.currency,result];
UIFont *font = [UIFont fontWithName:#"Avenir-Medium" size:14.0];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.alignment = NSTextAlignmentCenter;
NSDictionary *attributes = #{
NSFontAttributeName : font,
NSParagraphStyleAttributeName : paragraphStyle,
NSForegroundColorAttributeName : [UIColor whiteColor]
};
CGSize textSize = [strData sizeWithAttributes:attributes];
CGRect textRect = CGRectMake(5, (image.size.height-textSize.height)/2 - 2, textSize.width , textSize.height);
UILabel *textLable = [[UILabel alloc]initWithFrame:textRect];
textLable.textColor = [UIColor whiteColor];
textLable.font = font;
textLable.text = strData;
UIImage *lightSymImg = [UIImage imageNamed:#"icon_lightning"];
UIImageView *lightImage = [[UIImageView alloc]init];
lightImage.image = lightSymImg;
CGRect imgRect = CGRectMake(textRect.origin.x+textRect.size.width, (image.size.height-lightSymImg.size.height)/2 - 2, lightSymImg.size.width,lightSymImg.size.height);
lightImage.frame = imgRect;
imgView.frame = CGRectMake(0, 0, imgRect.size.width + imgRect.origin.x+5, image.size.height);
imgView.image = image;
for (UIView *view in [annotationView subviews])
{
[view removeFromSuperview];
}
annotationView.annotation = annotation;
[annotationView addSubview:imgView];
[annotationView addSubview:textLable];
[annotationView addSubview:lightImage];
annotationView.enabled = YES;
annotationView.canShowCallout = NO;
}
return annotationView;
}
And in didSelect method i have written this code for Present a view Controller
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
NSLog(#"didSelectAnnotationView");
if ([view.annotation isKindOfClass:[FBAnnotationCluster class]]) {
NSLog(#"FBAnnotationCluster select annotation");
}
else{
SpotDetailVC *locDetailVC = [[UIStoryboard storyboardWithName:#"SpotDetail" bundle:nil] instantiateViewControllerWithIdentifier:#"SpotDetailVC"];
[self presentViewController:navController animated:YES completion:nil];
}
}
Now When i click on annotation for the first Time it works but after dismiss that view again click on Same annotation it does not works.
Please help, i know it's Silly mistake but i am not able to configure out that one.

Make Google Maker like a Toggle Button

Actually i am adding iconview to marker and change to another iconview when one tap on that marker. this can be easily done by adding iconview in didTapMarker delegate method. But How to change to default view when one select to another Marker. just like Toggle Button
- (void)viewDidLoad
{
for(int i=0;i<lat.count;i++)
{
CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[lat objectAtIndex:i]doubleValue],[[longit objectAtIndex:i]doubleValue]);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, 60)];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 69, 21)];
label.text = #"Hello";
label.font = [UIFont systemFontOfSize:10];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor colorWithRed:24.0/255.0 green:59.0/255.0 blue:91.0/255.0 alpha:1.0];
label.backgroundColor = [UIColor colorWithRed:177.0/255.0 green:177.0/255.0 blue:177.0/255.0 alpha:1.0];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 21, 69, 38)];
[btn setImage:[UIImage imageNamed:#"map2_"] forState:UIControlStateNormal];
[view addSubview:label];
[view addSubview:btn];
marker.iconView = view;
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.map = _mapView;
}
}
and in didTapMarker delegate method
-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, 60)];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 69, 21)];
label.text = #"Hello";
label.font = [UIFont systemFontOfSize:10];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:32.0/255.0 green:139.0/255.0 blue:58.0/255.0 alpha:1.0];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 21, 69, 38)];
[btn setImage:[UIImage imageNamed:#"map3_"] forState:UIControlStateNormal];
[view addSubview:label];
[view addSubview:btn];
marker.iconView = view;
return YES;
}
You can userData property of GMSMarker for that, first set the userData with all your marker, so add this line inside your for loop of viewDidLoad where you are adding marker on Map.
marker.userData = #{#"isSelected":[NSNumber numberWithInt:0]};
Now on didTapMarker check like this
-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 69, 60)];
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 69, 21)];
label.text = #"Hello";
label.font = [UIFont systemFontOfSize:10];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor colorWithRed:32.0/255.0 green:139.0/255.0 blue:58.0/255.0 alpha:1.0];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 21, 69, 38)];
NSNumber *number = [marker.userData objectForKey:#"isSelected"];
if ([number integerValue] == 0) {
[btn setImage:[UIImage imageNamed:#"map3_"] forState:UIControlStateNormal];
marker.userData = #{#"isSelected":[NSNumber numberWithInt:1]};
}
else {
[btn setImage:[UIImage imageNamed:#"map2_"] forState:UIControlStateNormal];
marker.userData = #{#"isSelected":[NSNumber numberWithInt:0]};
}
[view addSubview:label];
[view addSubview:btn];
marker.iconView = view;
return YES;
}

Multiple info windows showing same text in iOS

I have implemented infoWindow to show data of my multiple markers. But all i can display is same data in all by info windows .
How to show data which is related to that marker, so that there should be no repetition ?
Here is my code :
for (int i = 0 ; i < jsonDataDict.count; i ++) {
NSDictionary *newDict = [jsonDataDict objectAtIndex:i ];
double latitude = [[newDict valueForKey:#"lat"]doubleValue];
double longitute = [[newDict valueForKey:#"lng"]doubleValue];
nameStr = [newDict valueForKey:#"name"];
countJson = i ;
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(latitude, longitute);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = [newDict valueForKey:#"name"];
// marker.icon = [UIImage imageNamed:#"pin11.png"];
marker.icon = [self image:[UIImage imageNamed:#"pinPopoye.png"] scaledToSize:CGSizeMake(75.0f, 60.0f)];
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.infoWindowAnchor = CGPointMake(1.1, 0.70);
marker.map = self.mapView;
[self mapView:self.mapView markerInfoWindow:marker];
}
}
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{ UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 25)];
customView.backgroundColor = [UIColor colorWithRed:71.0/255.0 green:65.0/255.0 blue:65.0/255.0 alpha:0.8];
customView.layer.cornerRadius = 5;
customView.layer.masksToBounds = YES;
// Orange Color ==== [UIColor colorWithRed:254.0/255.0 green:165.0/255.0 blue:4.0/255.0 alpha:0.5];
UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 10)];
nameLabel.text = nameStr;
nameLabel.textColor = [UIColor whiteColor];
nameLabel.textAlignment = NSTextAlignmentCenter;
nameLabel.font = [UIFont systemFontOfSize:8.0];
[customView addSubview:nameLabel];
return customView;
}
Replace this statement:
nameLabel.text = nameStr;
with:
nameLabel.text = marker.title;
The problem is your using a shared NSString, nameStr, which gets overwritten at each iteration of your for loop. So, all label share the same string value when they are finally displayed. You could also do:
nameLabel.text = [nameStr copy];
and it should work -- but I think that using nameStr in your code was just a remnant of some previous "hack".

how to show multiple info window of GMS mapView?

I want to add multiple info windows to appear at the same time with out tapping on the marker .
How to implement this ?
Here is my code to add multiple markers and adding a infoWindow?
for (int i = 0 ; i < jsonDataDict.count; i ++) {
NSDictionary *newDict = [jsonDataDict objectAtIndex:i ];
double latitude = [[newDict valueForKey:#"lat"]doubleValue];
double longitute = [[newDict valueForKey:#"lng"]doubleValue];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(latitude, longitute);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
nameOfPlace = [newDict valueForKey:#"name"];
// distanceOfPlace = [newDict valueForKey:#"distance"];
marker.icon = [self image:[UIImage imageNamed:#"pinPopoye.png"] scaledToSize:CGSizeMake(75.0f, 60.0f)];
marker.appearAnimation = kGMSMarkerAnimationPop;
marker.infoWindowAnchor = CGPointMake(1.1, 0.70);
marker.map = self.mapView;
[self.mapView setSelectedMarker:marker];
//[self mapView:self.mapView markerInfoWindow:marker];
}
}
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 25)];
customView.backgroundColor = [UIColor colorWithRed:71.0/255.0 green:65.0/255.0 blue:65.0/255.0 alpha:0.8];
customView.layer.cornerRadius = 5;
customView.layer.masksToBounds = YES;
nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 10)];
nameLabel.text = nameOfPlace;
nameLabel.textColor = [UIColor whiteColor];
nameLabel.textAlignment = NSTextAlignmentCenter;
nameLabel.font = [UIFont systemFontOfSize:8.0];
[customView addSubview:nameLabel];
distanceLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 12, 60, 10)];
distanceLabel.text = distanceOfPlace;
distanceLabel.textColor = [UIColor whiteColor];
distanceLabel.textAlignment = NSTextAlignmentCenter;
distanceLabel.font = [UIFont systemFontOfSize:8.0];
[customView addSubview:distanceLabel];
return customView;
}

ios : how to add uiLabel on top of the background image?

I am trying to add the uiLabel on top of the uiImageVIew which is the background image. When it comes to adding the uiLabel on top of the uiImageView, the uilabel cannot be aded when testing and running. Would you please tell me the alternatives or precautions if doing so ?
The below is my code :
#implementation CoverViewController
- (void)viewDidLoad {
[super viewDidLoad];
_container = [[UIView alloc] initWithFrame:[self.view bounds]];
[self setTapDemo :[UIImage imageNamed:#"cover_1_d.png"] ] ;
}
- (void) setTapDemo: (UIImage *) cover {
_image = [UIImage imageNamed:#"shaded_region.png"];
_imageShaded = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[_imageShaded setImage:_image];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[imageView setImage: cover ];
_imageShaded.userInteractionEnabled = YES;
UITapGestureRecognizer *myGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(touchesBegan:)];
myGesture.numberOfTapsRequired = 1;
myGesture.delegate=self;
[_imageShaded addGestureRecognizer:myGesture];
[_imageShaded setContentMode:UIViewContentModeScaleAspectFill];
NSString * text = #"Quad name:";
CGSize labelSize = CGSizeMake(60, CGFLOAT_MAX);
UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, labelSize.width, labelSize.height)];
fromLabel.text = text;
fromLabel.numberOfLines = 1;
fromLabel.lineBreakMode = NSLineBreakByWordWrapping;
fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
fromLabel.adjustsFontSizeToFitWidth = YES;
fromLabel.minimumScaleFactor = 10.0f/12.0f;
fromLabel.clipsToBounds = YES;
fromLabel.backgroundColor = [UIColor clearColor];
fromLabel.textAlignment = NSTextAlignmentLeft;
[_imageShaded addSubview:fromLabel];
[imageView addSubview:fromLabel];
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
[_container addSubview:fromLabel];
[self.view addSubview:_container];
[self.view sendSubviewToBack:_container];
}
Check This
- (void) setTapDemo: (UIImage *) cover {
_image = [UIImage imageNamed:#"images.jpg"];
_imageShaded = [[UIImageView alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height)];
[_imageShaded setImage:_image];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 60, self.view.frame.size.width, self.view.frame.size.height)];
[imageView setImage: cover ];
_imageShaded.userInteractionEnabled = YES;
UITapGestureRecognizer *myGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(touchesBegan:)];
myGesture.numberOfTapsRequired = 1;
myGesture.delegate=self;
[_imageShaded addGestureRecognizer:myGesture];
[_imageShaded setContentMode:UIViewContentModeScaleAspectFill];
NSString * text = #"Quad name:";
// CGSize labelSize = CGSizeMake(60, CGFLOAT_MAX);
UILabel *fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, 300, 40)];
fromLabel.text = text;
fromLabel.textColor = [UIColor greenColor];
fromLabel.numberOfLines = 1;
fromLabel.lineBreakMode = NSLineBreakByWordWrapping;
fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines; // or UIBaselineAdjustmentAlignCenters, or UIBaselineAdjustmentNone
fromLabel.adjustsFontSizeToFitWidth = YES;
fromLabel.minimumScaleFactor = 10.0f/12.0f;
fromLabel.clipsToBounds = YES;
fromLabel.backgroundColor = [UIColor clearColor];
fromLabel.textAlignment = NSTextAlignmentLeft;
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
[self.view addSubview:_container];
[self.view sendSubviewToBack:_container];
[imageView addSubview:fromLabel];
}
You are adding your UILabel more than once on different views. you should add it on a single view at a time;
//[_imageShaded addSubview:fromLabel]; // 1
//[imageView addSubview:fromLabel]; // 2
[_container addSubview:_imageShaded];
[_container addSubview:imageView];
//[_container addSubview:fromLabel]; //3

Resources