Search code examples
iphoneipadios6mkmapview

how to hide current Location annotation from mkmapview


In my application i have used the MKmapview,I want to hide the user current location annotation point,Here my code

 - (void)viewDidLoad
 {
  [super viewDidLoad];
  appDel=(AppDelegate *)[UIApplication sharedApplication].delegate;
  DatabaseController *dbObj=[[DatabaseController alloc] init];
  NSString *query=[NSString stringWithFormat:@"select * from petBoundarySettings where petId=%@",self.petID];
  NSMutableArray *alertSettingArray=[dbObj getPetAlertSerrings:query :[appDel getDBPath]];
 if([alertSettingArray count]>0){
    distance=[[[alertSettingArray objectAtIndex:0] objectForKey:@"distance"] integerValue];
 address=[[alertSettingArray objectAtIndex:0] objectForKey:@"address"];
 lat2=[[alertSettingArray objectAtIndex:0] objectForKey:@"lat"] ;
 lon2=[[alertSettingArray objectAtIndex:0] objectForKey:@"lang"] ;
}
UIImageView *imageNav = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"sml-cat_03.png"]];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imageNav];
[imageNav release];
[dbObj release];
MKCoordinateSpan span;
span.latitudeDelta=.01;
span.longitudeDelta=.01;
MKCoordinateRegion region;
//distance=appDel.alertDistance;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = nil;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
currentAnnotation=[[MyAnnotations alloc]init];
NSLog(@"GL%f",appDel.getlat);
NSLog(@"GN%f",appDel.getlon);
regionCoordinate.latitude =[lat2 floatValue];
regionCoordinate.longitude = [lon2 floatValue];
currentAnnotation.coordinate=regionCoordinate;
currentAnnotation.title=@"Boundary Location";
currentAnnotation.subtitle=appDel.address;
     region.center=CLLocationCoordinate2DMake(regionCoordinate.latitude,regionCoordinate.longitude);

region.span=span;
[_myMapView setRegion:region animated:YES];
[_myMapView regionThatFits:region];

region1=region;
petAnnotation=[[MyAnnotations alloc]init];
petCoordinate.latitude = +11.028549739;
petCoordinate.longitude = +76.89644586;
petAnnotation.coordinate=petCoordinate;
petAnnotation.title=@"My Pet Location";
petAnnotation.subtitle=@"Vadavalli";
MKCircle *circle = [MKCircle circleWithCenterCoordinate:regionCoordinate radius:distance];
[_myMapView addOverlay:circle];
CLLocation *whereIAm = [locationManager location];
NSLog(@"MI%@",whereIAm);
[_myMapView addAnnotation:currentAnnotation];
MKMapPoint p1 = MKMapPointForCoordinate(regionCoordinate);
MKMapPoint p2 = MKMapPointForCoordinate(petCoordinate);
CLLocationDistance dist = MKMetersBetweenMapPoints(p1, p2);
i=0;
[self getPetData];
timer= [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(getPetData) userInfo:nil repeats:YES];
if(appDel.checkGPS==NO)
{
    [self getPetDataFromGPS];
}
}

How to hide the current location from mkmapview,Please help me to sort out.


Solution

  • MKMapView has a property named showsUserLocation that you can set to determine whether the user's location can be displayed. However, I see that you're not setting it in code, and the default value is NO.

    If you're using a Xib or Storyboard, check the MKMapView in there, as there is a checkbox for this behaviour in the attributes inspector. (Shows User Location)