You can get user location using the following code
-(void)viewDidLoad{
CLLocationManager *locationManager=[[CLLocationManager alloc] init];
locationManager.delegate=self;//THIS IS IMPORTANT
[locationManager startUpdatingLocation];
}
When you tell the location manager to get the locations if Allowed
the locationmanager
calls its delegate method see below
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
//newLocation is your current Location
self.userLocation=newLocation;//Once you got the location generate the places..
[self generatePlaces];
[manager stopUpdatingLocation];
}
-(void)generatePlaces{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:postcodeForMap
completionHandler:^(NSArray* placemarks, NSError* error){
NSLog(@"Co-ordinate geocode is %@", [placemarks objectAtIndex:0]);
for (CLPlacemark* aPlacemark in placemarks)
{
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
//EDITED
MKPlacemark *mPlacemark = [[MKPlacemark alloc] initWithCoordinate:self.userLocation.coordinate addressDictionary:nil];
MKCoordinateRegion region = mapView.region;
region.center = placemark.region.center;
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;
[mapView setRegion:region animated:YES];
[mapView addAnnotation:placemark];
[mapView addAnnotation:mPlacemark];
}
}
];
}