2

I am adding MKPointAnnotation annotation using MKMapView.

I have given image to MKPointAnnoation but blue dot is not removed.

-(void)updateMarkerWithUserLocation
{
    NSString *name=  [[NSUserDefaults standardUserDefaults]valueForKey:@"userName"];

    for (MKPointAnnotation *annotation in _mapView.annotations)
    {
        [_mapView removeAnnotation:annotation];
    }
    NSNumber * latitude = [NSNumber numberWithFloat:[[NSUserDefaults standardUserDefaults]floatForKey:@"currentLatitude"]];
    NSNumber * longitude = [NSNumber numberWithFloat:[[NSUserDefaults standardUserDefaults]floatForKey:@"currentLongitude"]];

    ////******   to add my location in the map of type MKPointAnnotation

    CLLocationCoordinate2D annotationCoord;

    annotationCoord.latitude = [latitude floatValue];
    annotationCoord.longitude = [longitude floatValue];

    MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
    annotationPoint.coordinate = annotationCoord;

    StrLocality=[[NSUserDefaults standardUserDefaults]valueForKey:@"StrLocality"];
    annotationPoint.title = name;
    annotationPoint.subtitle=StrLocality;

    [_mapView addAnnotation:annotationPoint];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKPointAnnotation class]])
    {
        // Try to dequeue an existing pin view first.
        MKAnnotationView *pinView = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomPinAnnotationView"];
        if (!pinView)
        {
            pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotationView"];
            //pinView.animatesDrop = YES;
            pinView.canShowCallout = YES;
            pinView.image = [UIImage imageNamed:@"user_location.png"];
            // pinView.calloutOffset = CGPointMake(5, 32);
        } else {
            pinView.annotation = annotation;
        }
        return pinView;
    }

    return nil;
}

enter image description here

Akshay
  • 109
  • 1
  • 8

2 Answers2

2

The blue dot is not removed because you have told the map to show the user's location, and until you tell it to stop showing the user's location it will keep showing the blue dot. Add [mapView setShowsuserLocation:NO] somewhere in your code to turn it off, if that's what you want to do.

Craig
  • 8,093
  • 8
  • 42
  • 74
  • i had set the [mapView setShowsuserLocation:NO] in view did load.But still it will show blue dot.Also i had add MktrackingUserBarButton in View did load.This may be the cause of blue dot because when i click on mktrackingUser bar button then it will show blue dot. – Akshay Jan 03 '14 at 11:37
  • Yes, setting showsUserLocation or setting the tracking mode to anything other than MKUserTrackingModeNone will show the blue dot. Usuallt people struggle to turn it on rather than turn it off. – Craig Jan 04 '14 at 01:41
  • I have found the solution for this.I use did annotate method for it. – Akshay Jan 06 '14 at 07:08
1

To set user location's custom image add these lines inside viewForAnnotation method,

if ([annotation isMemberOfClass:[MKUserLocation class]]) {
   //code to set current location pin's image
}
Engnyl
  • 1,380
  • 16
  • 24
  • I had written these lines they are working fine. But the main problem is when i click on MKTrackingBarButton then i will show blue dot. I have no idea how to remove blue dot when click on MKTrackingBarButton. – Akshay Jan 03 '14 at 11:44
  • Here you can find about MKTrackingBarButtonItem http://stackoverflow.com/questions/16830861/how-to-detect-when-mkusertrackingbarbuttonitem-is-used . Referring to my previous answer, you can switch the current user location's to an UIImage or blue dot. – Engnyl Jan 03 '14 at 11:58
  • This answer is very useful if you are trying to show a different image instead of the blue dot at the user's location. It will move just as the blue dot does. But if you are just trying to stop showing the blue dot, as this question asks, then it is not so useful. – Craig Jan 04 '14 at 01:40