I read the current location's latitude and longitude values and then pin that location in iPhone successfully. Now I want to read that place name using this latitude and longitude values.
I used the following code to read the find the current location:
- (void)mapView:(MKMapView *)mapView1 didUpdateUserLocation:(MKUserLocation *)userLocation{
CLLocation *whereIAm = userLocation.location;
NSLog(@"I'm at %@", whereIAm.description);
latitude = whereIAm.coordinate.latitude;
longitude = whereIAm.coordinate.longitude;
NSLog(@"LAT : %f",latitude);
NSLog(@"LONG : %f",longitude);
mapView.mapType=MKMapTypeStandard;
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude =latitude; //22.569722 ;
region.center.longitude = longitude; //88.369722;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:self];
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = @" Welcome";
ann.subtitle = @"Hi";
ann.coordinate = region.center;
[mapView addAnnotation:ann];
}
- (void)viewDidLoad {
[super viewDidLoad];
mapView.showsUserLocation = YES;
mapView.delegate = self;
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation: (id<MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
}
[mapView.userLocation setTitle:@"I am here"];
return pinView;
}