1

I have a search bar with allows me to fetch Location, Latitude and Longitude. When i get the values, the map shows the annotation perfectly.

Problem : When i select another location, lat, long previous data remains there.

What i need : I want to remove that previous particular location when ever i click the search button.

Code :

double searchLAT = [_searchedLat doubleValue];
double searchLONG = [_searchedLong doubleValue];

MKUserLocation *userlocation = [[MKUserLocation alloc] init];
userlocation.coordinate = CLLocationCoordinate2DMake(searchLAT, searchLONG);

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userlocation.coordinate, 700000, 700000);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];

MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = CLLocationCoordinate2DMake(searchLAT,searchLONG);
[self.mapView addAnnotation:point]; 
TheTravloper
  • 236
  • 5
  • 16

1 Answers1

0

Do not initialize userlocation in the function. Make it global for your controller so only lat-long change but for MKUserLocation not allocate memory every time.

Mirant
  • 308
  • 2
  • 13